hagopj13 / node-express-boilerplate

A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose
MIT License
6.87k stars 2.02k forks source link

Socket support #15

Open kartikey54 opened 4 years ago

kartikey54 commented 4 years ago

Hi, Excellent boilerplate! How about adding support for sockets in this to make a more complete boilerplate? Also instructions on deployment using Docker/native would be very helpful. Thanks.

hagopj13 commented 4 years ago

@kartikey54 Thanks a lot for the suggestions. I will soon add instructions on deployment. Concerning sockets, I will think about that. Is there a use case of sockets you know of that could be useful for almost everyone using this boilerplate? I tend to keep the features that are most commonly used, so that when people clone the boilerplate, they won't have to remove a lot of code before having something workable.

kartikey54 commented 4 years ago

Thank you for the response! Yes, since you built authentication into the app i think another widely used feature would be notifications. Almost all modern day apps have some kind of notification mechanism. (Another popular use case is chat but notification are still more widely used). It would also be a good addition to make this boilerplate stand out.

On Mon, 25 May 2020 at 6:31 PM, Hagop Jamkojian notifications@github.com wrote:

@kartikey54 https://github.com/kartikey54 Thanks a lot for the suggestions. I will soon add instructions on deployment. Concerning sockets, I will think about that. Is there a use case of sockets you know of that could be useful for almost everyone using this boilerplate? I tend to keep the features that are most commonly used, so that when people clone the boilerplate, they won't have to remove a lot of code before having something workable.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hagopj13/node-express-mongoose-boilerplate/issues/15#issuecomment-633561071, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFMZBUDZI5VZHF7ZXMALK4TRTJTZRANCNFSM4NIYFQTQ .

hagopj13 commented 4 years ago

@kartikey54 I like the idea of having notifications, thanks. I will set this as "help wanted" for now so that other people can contribute, and if no one picks it up after some time, I will do it.

khkmalki commented 4 years ago

Unbelievable work !!! I believe this is one of the best nodejs boilerplates I have ever seen.

The funny thing is I have a project coming and I was thinking of having node as Backend. I thought of boilerplates and searched npmjs only to find you actually deployed this piece of art just a few days ago.

I will try to do what I can to help also.

hagopj13 commented 4 years ago

@khkmalki thank you for the kind words. I'm glad you find it useful.

pxl-live commented 4 years ago

@hagopj13 I also really appreciate your boilerplate! Likewise web sockets would really be appreciated for our use case. I have tried implementing myself but just cant seem to get it to work

/node-express-mongoose-boilerplate/node_modules/engine.io/lib/server.js:458 var listeners = server.listeners('request').slice(0); ^

TypeError: Cannot read property 'listeners' of undefined

Have tried adding the following to app.js and index.js:

const http = require('http').createServer(app);
const io = require('socket.io')(http);
io.listen();
kartikey54 commented 4 years ago

@hagopj13 I also really appreciate your boilerplate! Likewise web sockets would really be appreciated for our use case. I have tried implementing myself but just cant seem to get it to work

/node-express-mongoose-boilerplate/node_modules/engine.io/lib/server.js:458 var listeners = server.listeners('request').slice(0); ^

TypeError: Cannot read property 'listeners' of undefined

Have tried adding the following to app.js and index.js:

const http = require('http').createServer(app);
const io = require('socket.io')(http);
io.listen();

Can you share a link to your repo?

pxl-live commented 4 years ago

@kartikey54 Sure!! I have forked and created my changes there.

https://github.com/pxl-live/node-express-mongoose-boilerplate

hagopj13 commented 4 years ago

@pxl-live I tried running the code in your fork and it worked (after adding the socket.io dependency). Are you still facing issues?

Bshah88 commented 4 years ago

@hagopj13 I was going through the code and you have build an awesome production ready boilerplate. Thanks for this. I would like to ask a question regarding the logout functionality. Are we removing the tokens from DB when user logs out? Please reply.... CC: @kartikey54 @pxl-live @AndreiEnache @khkmalki

hagopj13 commented 4 years ago

@Bshah88 thanks for the kind words. We don't have a logout API yet. Please open a separate issue for that.

Shidooo commented 3 years ago

How do you @hagopj13 use the solution of @pxl-live ? I've tested it on my side and it doesn't seem to work...

All requests to my socket are catched here app.use((req, res, next) => { next(new ApiError(httpStatus.NOT_FOUND, 'Not found')); }); Looks like the socket was not attached to the application at all and everything passes through.

error: GET /socket.io/?EIO=3&transport=polling&t=NTtgBqg 404 - 54.230 ms - message: Not found

Thanks for helping

Shidooo commented 3 years ago

I found an alternative

let server = require('http').createServer(app);
mongoose.connect(config.mongoose.url, config.mongoose.options).then(() => {
  logger.info('Connected to MongoDB');

  const options = {cors: true, origins:'*'};
  const io = require('socket.io')(server, options);
  io.on('connection', socket => { 
    logger.info(`Connected ${socket.id}`);
  });

  server.listen(config.port, () => {
    logger.info(`Listening to port ${config.port}`);
  });
});
hacker8-eng commented 3 years ago

Oi

srikanth-interakt commented 3 years ago

Thanks for the good work. This is an excellent boilerplate I've seen so far.

Yes, Can we get sockets added to this boilerplate ?