Node.js

deepstream can also be installed as an NPM package and offers a Node.js API to interact with it programmatically.

This can be useful to build custom authentication or permissioning logic or if you want to use the server on top of a HTTP server like Express. You can view the full Node.js API here.

Install the server via npm

npm install deepstream.io

Create a js file, e.g. start.js with the following content

const DeepstreamServer = require('deepstream.io')
const C = DeepstreamServer.constants
/*
The server can take
1) a configuration file path
2) null to explicitly use defaults to be overriden by server.set()
3) left empty to load the base configuration from the config file located within the conf directory.
4) pass some options, missing options will be merged with the base configuration
*/
const server = new DeepstreamServer({
  host: 'localhost',
  port: 6020
})

/*
Optionally you can specify settings to set in complex objects, such as dataTransforms, a HTTPServer
or a plugin which you want to reuse within your application
*/
server.set('dataTransforms', [{
  topic: C.TOPIC.RPC,
  action: C.ACTIONS.REQUEST,
  transform: function(data, metaData) {}
}])

// start the server
server.start()

run the file with node

node start.js

Using the deepstream client in Node.js

The deepstream javascript client can be installed via NPM and used in Node.js.

npm install deepstream.io-client-js
const deepstream = require('deepstream.io-client-js')
const client = deepstream('localhost:6020').login()
Need support, architectural consulting or training? Buy Support