Nocturnal Prancing Mosquito


    2.2.2 • Public • Published


    Version npm Custom badge

    m2m is a lightweight real-time communication library for developing client-server or pub-sub applications using the machine-to-machine framework node-m2m.

    Your application will be composed of two or more independent service modules running on their own processes similar to microservices pattern.

    Deploy private device servers on the fly from anywhere without the usual heavy infrastructure involved in provisioning an on-premise physical servers.

    Create Channel, HTTP and GPIO ( for Raspberry Pi devices ) resources on your remote devices for client consumption.

    Your device servers will be instantly available and accessible through its user-assigned device id from anywhere.

    Access to clients and devices is restricted to authenticated and authorized users only. All communications traffic between clients and devices are fully encrypted using TLS.

    To use this library, users will need to register with node-m2m.

    Start your first m2m application from the quick tour guide.

    Table of contents

    1. Supported Platform
    2. Node.js version requirement
    3. Installation
    4. Quick Tour
    5. API

    Supported Platform

    • Raspberry Pi Models: B+, 2, 3, Zero & Zero W, Compute Module 3, 3B+, 3A+, 4B (generally all 40-pin models)
    • Linux
    • Windows
    • Mac

    Node.js version requirement

    • Node.js versions: 10.x, 11.x, 12.x, 14.x, 16.x. Ideally the latest LTS version.


    $ npm install m2m

    Raspberry Pi peripheral access (GPIO, I2C, SPI and PWM).

    For projects requiring raspberry pi peripheral access such as GPIO, I2C, SPI and PWM, you will need to install array-gpio module.

    $ npm install array-gpio

    Using the Browser Interface

    Remote Application Code Editing

    Using the browser interface, you can download, edit and upload your application code from your remote clients and devices from anywhere.

    To allow the browser to communicate with your application, add the following m2mConfig property to your project's package.json.

    "m2mConfig": {
      "code": {
        "allow": true,
        "filename": "device.js"

    Set the property allow to true and provide the filename of your application.

    From the example above, the filename of the application is device.js. Replace it with the actual filename of your application.

    Application Auto Restart

    Using the browser interface, you may need to restart your application after a module update, code edit/update, or a remote restart command.

    Node-m2m uses nodemon to restart your application.

    $ npm install nodemon

    You can add the following nodemonConfig and scripts properties in your project's npm package.json as auto-restart configuration.

    "nodemonConfig": {
      "verbose": true,
      "restartable": "rs",
      "ignore": [".git", "public"],
      "ignoreRoot": [".git", "public"],
      "execMap": {"js": "node"},
      "watch": ["node_modules/m2m/mon"],
      "ext": "js,json"
    "scripts": {
      "start": "nodemon device.js"

    From the example above, the filename of the application is device.js. Replace it with the actual filename of your application when adding the scripts property. Then restart your node process using npm start command as shown below.

    $ npm start

    For other custom nodemon configuration, please read the nodemon documentation.

    Code Edit and Auto Restart Automatic Configuration

    Install nodemon.

    $ npm install nodemon

    To configure your package.json for code editing and auto-restart without manual editing of package.json, start your node process with -config flag.

    m2m will attempt to configure your package.json by adding/creating the m2mConfig, nodemonConfig, and scripts properties to your existing project's package.json. If your m2m project does not have an existing package.json, it will create a new one.

    Assuming your application filename is device.js, start your node application as shown below.

    $ node device -config

    Stop your node process using ctrl-c. Check and verify your package.json if it was properly configured.

    If the configuration is correct, you can now run your node process using npm start command.

    $ npm start

    Your application should restart automatically after a remote code update, an npm module update, a remote restart command from the browser interface.

    Naming your Client Application for Tracking Purposes

    Unlike the device/server applications, users can create client applications without registering it with the server.

    Node-m2m tracks all client applications through a dynamic client id from the browser. If you have multiple clients, tracking all your clients by its client id is not easy.

    You can add a name, location and a description properties to your clients as shown below.

    This will make it easy to track all your clients from the browser interface.

    const m2m = require('m2m');
    const client = new m2m.Client({name:'Main client', location:'Boston, MA', description:'Test client app'});
    client.connect(() => {


    npm i m2m

    DownloadsWeekly Downloads






    Unpacked Size

    382 kB

    Total Files


    Last publish


    • ealegrid