These Examples demonstrate how to use the Node.js wrapper for the SDK.

Note: NodeJS wrapper will no longer be supported and was removed from the SDK repository.

Latest version that includes the reference code is: v2.53.1

List of Examples

Sample code source code is available on GitHub

For full Node.js AP documentation please open wrappers/nodejs/doc/index.html for full reference document. If it isn't there, run the following commands to generate it:

cd wrappers/nodejs
node scripts/generate-doc.js
# ExampleDescriptionCamera/SKULink to GitHub
1Stream Depth and ColorThis examples demonstrates how to stream depth and colorD400/L500nodejs-capture
2PointcloudThis examples demonstrates pointcloude visualizationD400/L500nodejs-pointcloud
3Remove background and alignDemonstrates
background removal by aligning depth images to color images
D400/L500nodejs-align
4Save to SiskDemonstrates how to save a png and csv files to diskD400/L500nodejs-save-to-disk
5Sensor ControlA tutorial for using the more advanced API that the RealSense SDK provides.D400/L500nodejs-sensor-control

Stream Depth and Color code example

#!/usr/bin/env node

// Copyright (c) 2017 Intel Corporation. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license
// that can be found in the LICENSE file.

'use strict';

const rs2 = require('../index.js');
const {GLFWWindow} = require('./glfw-window.js');
const {glfw} = require('./glfw-window.js');

// A GLFW Window to display the captured image
const win = new GLFWWindow(1280, 720, 'Node.js Capture Example');

// Colorizer is used to map distance in depth image into different colors
const colorizer = new rs2.Colorizer();

// The main work pipeline of camera
const pipeline = new rs2.Pipeline();

// Start the camera
pipeline.start();

while (! win.shouldWindowClose()) {
  const frameset = pipeline.waitForFrames();
  // Build the color map
  const depthMap = colorizer.colorize(frameset.depthFrame);
  if (depthMap) {
    // Paint the images onto the window
    win.beginPaint();
    const color = frameset.colorFrame;
    glfw.draw2x2Streams(win.window, 2,
        depthMap.data, 'rgb8', depthMap.width, depthMap.height,
        color.data, 'rgb8', color.width, color.height);
    win.endPaint();
  }
}

pipeline.stop();
pipeline.destroy();
win.destroy();
rs2.cleanup();

Installation and Build Guidelines

Please refer to installation guideline at Node.js Installation and build guidelines