moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

running examples #622

Open gilesbradshaw opened 7 years ago

gilesbradshaw commented 7 years ago

I am trying to run mongodb example with

node examples/mongodb/start.js

but it just exists straight away..

mcollina commented 7 years ago

Does it output anything?

gilesbradshaw commented 7 years ago

no but if I change start.js to

'use strict'

var mosca = require('../../');
var config = require('./config');

var server = new mosca.Server(config);

server.on('error', function(err){
  console.log(err);
});

server.on('ready', function(){
  console.log('Mosca server is up and running');
});

console.log('here i am');
console.log(config)

it says..

here i am
{ id: 'mymosca',
  stats: false,
  logger: { level: 'debug' },
  backend: { type: 'mongodb', url: 'mongodb://localhost:27017/mosca' },
  persistence: 
   { factory: { [Function: MongoPersistence] super_: [Object] },
     url: 'mongodb://localhost:27017/mosca' } }

so it is definitely running the code but node isn't waiting for the event emitters to fire..

gilesbradshaw commented 7 years ago

Ok here we go -

you have

var server = new mosca.Server(config);

but if I do..

var server = new mosca.Server(config, function() {
  console.log('Mosca server is up and running')
});

it doesn't exit straight away..

mcollina commented 7 years ago

that function might contain an error as first argument