Same-machine transport

Unix sockets + Windows named pipes

Use serve and connectTo when both processes share a machine. node-ipc maps the logical path to the native local transport.

Why local sockets

No network hop

Traffic stays on the machine and avoids TCP or UDP routing.

One logical name

The default path combines socketRoot, appspace, and service id.

Native mapping

Unix uses a filesystem socket path; Windows converts that logical path to \\.\pipe\….

Server

import ipc from 'node-ipc';

ipc.config.id = 'inventory';

ipc.serve(() => {
  ipc.server.on('lookup', (sku, socket) => {
    ipc.server.emit(socket, 'lookup.result', {sku, available: true});
  });
});

ipc.server.start();

Omit the path to use socketRoot + appspace + id, or pass an explicit logical path as the first argument.

Client

ipc.connectTo('inventory', () => {
  ipc.of.inventory.on('connect', () => {
    ipc.of.inventory.emit('lookup', 'SKU-42');
  });

  ipc.of.inventory.on('lookup.result', result => {
    console.log(result);
    ipc.disconnect('inventory');
  });
});

The client is immediately available at ipc.of.inventory; wait for connect before emitting.

Paths and ownership

PlatformDefault shapeOperational concern
Linux / macOSDerived runtime directory + app.inventoryVerify the actual directory owner and mode; they define who can reach the socket.
Windows\\.\pipe\node-ipc-user-app.inventoryreadableAll and writableAll request broader access; leave them false unless required.
Endpoint ownership is deployment-specific.

Local socket permissions do not authenticate messages. Verify the actual directory owner, mode, endpoint location, and host-user boundary in the environment where the service runs.

Cleanup and clustering

  • Keep unlink: true for one owner of one socket path.
  • Set unlink: false only when a clustered design owns deletion explicitly.
  • Call ipc.disconnect(id) for clients and ipc.server.stop() for servers during orderly shutdown.
  • Treat a stale socket path as an operational failure to investigate, not a reason to broaden permissions.