Playground recipe · round trip

Create. Serialize. Receive.

The same two-field envelope survives object use, JSON transport, and reconstruction without a build step.

js-message works with bundlers and without a bundler.

Bundlers resolve the bare js-message import normally. Native browser ESM resolves it through a standard import map, with no build or transpilation step.

Complete source

import Message from 'js-message';

const outgoing = new Message({
    type: 'user.updated',
    data: {
        id: 42,
        active: true
    }
});

console.log('object', outgoing.toJSON());
console.log('wire', outgoing.JSON);

const incoming = new Message(outgoing.JSON);
console.log('received', incoming.toJSON());

What to inspect

  • toJSON() exposes the plain transport envelope.
  • JSON emits the exact wire string.
  • The receiving constructor restores the same type and data.