1

i try to run my first deepstream.io server from this link but i get this error :

enter image description here

error:

CONNECTION_ERROR | Error: listen EADDRINUSE 127.0.0.1:3003
PLUGIN_ERROR | connectionEndpoint wasn't initialised in time
f:\try\deep\node_modules\deepstream.io\src\utils\dependency-
initialiser.js:96
throw error
^

Error: connectionEndpoint wasn't initialised in time
at DependencyInitialiser._onTimeout 
(f:\try\deep\node_modules\deepstream.io\src\utils\dependency-
initialiser.js:94:17)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)

and this is my code:

const DeepStreamServer = require("deepstream.io")
const C = DeepStreamServer.constants;
const server = new DeepStreamServer({
  host:'localhost',
  port:3003
})

server.start();
MBehtemam
  • 7,865
  • 15
  • 66
  • 108

3 Answers3

4

In deepstream 3.0 we released our HTTP endpoint, by default this runs alongside our websocket endpoint.

Because of this, passing the port option at the root level of the config no longer works (it overrides both the HTTP and websocket port options, as you can see in the screen capture provided, both endpoints are trying to start on the same port).

You can override each of these ports as follows:

const deepstream = require('deepstream.io')

const server = new deepstream({
  connectionEndpoints: {
    http: {
      options: {
        port: ...
      }
    },
    websocket: {
      options: {
        port: ...
      }
    }
  }
})
server.start()

Or you can define your config in a file and point to that while initialising deepstream[1].

[1] deepstream server configuration

Alex Harley
  • 353
  • 1
  • 3
  • 13
1

One solution that i find is passing empty config object so inseted of :

const server = new DeepStreamServer({
  host:'localhost',
   port:3003
})

i'm just using this :

 const server = new DeepStreamServer({})

and now everything work's well.

MBehtemam
  • 7,865
  • 15
  • 66
  • 108
1

All the bellow is for Version 4.2.2 (last version by now)

I was having the same Port in use or config file not found errors. And i was using typescript and i didn't pay attention too to the output dir and build (which can be a problem when one use typescript and build). I was able to run the server in the end. And i had a lot of analysis.

I checked up the code source and i have seen how the config is loaded

const SUPPORTED_EXTENSIONS = ['.yml', '.yaml', '.json', '.js']
const DEFAULT_CONFIG_DIRS = [
  path.join('.', 'conf', 'config'), path.join('..', 'conf', 'config'),
  '/etc/deepstream/config', '/usr/local/etc/deepstream/config',
  '/usr/local/etc/deepstream/conf/config',
]

DEFAULT_CONFIG_DIRS.push(path.join(process.argv[1], '..', 'conf', 'config'))
DEFAULT_CONFIG_DIRS.push(path.join(process.argv[1], '..', '..', 'conf', 'config'))

Also i tested different things and all. Here what i came up with:

  • First of all if we don't precise any parameter in the constructor. A config from the default directories will get to load. If there isn't then the server fail to run. And one of the places where we can put a config is ./conf in the same folder as the server node script.

  • Secondly we can precise a config as a string path (parameter in the constructor). config.yml or one of the supported extensions. That will allow the server to load the server config + the permission.yml and users.yml configs. Which too are supposed to be in the same folder. If not in the same folder there load will fail, and therefor the permission plugin will not load. And so does the users config. And no fall back to default will happen.

  • Thirdly the supported extensions for the config files are: yml, yaml, json, js.

  • In nodejs context. If nothing precised. There is no fallback to some default config. The config need to be provided in one of the default folders, or by precising a path to it. Or by passing a config object. And all the optional options will default to some values if not provided ( a bit bellow there is an example that can show that ). Know however that precising an end point is very important and required.

  • To precise the path, we need to precise the path to the config.yml file (the server config) [example: path.join(__dirname, './conf/config.yml')]. Then from the same dir permission.yml and users.yml will be retrieved (the extension can be any of the supported one). We can not precise a path to a directory, it will fail.

  • We can precise the path to permission config or user config separatly within config.yaml as shown bellow:

# Permissioning example with default values for config-based permissioning
permission:
  type: config
  options:
    path: ./permissions.yml
    maxRuleIterations: 3
    cacheEvacuationInterval: 60000
  • Finally we can pass an object to configure the server, or by passing null as a parameter and use .set methods (i didn't test the second method). For configuring the server we need to follow the same structure as the yml file. With sometimes a bit different naming. The typescript declaration files or types show us the way. With an editor like vscode. Even if we are not using typescript we can keep get the auto completion and type definitions. And the simplest for equivalent to the previous version is :
const webSocketServer = new Deepstream({
    connectionEndpoints: [
        {
            type: 'ws-websocket',
            options: {
                port: 6020,
                host: '127.0.0.1',
                urlPath: '/deepstream'
            }
        }
    ]
});

webSocketServer.start();
  • the above is the new syntax and way.
const server = new DeepStreamServer({
  host:'localhost',
   port:3003
})

^^^^^^^ is completely deprecated and not supported in version 4 (the doc is not updated).

Mohamed Allal
  • 17,920
  • 5
  • 94
  • 97