vgokul129 vgokul129 - 1 year ago 107
Node.js Question

next() call in express-ws module in nodejs

I came across a sample code for my webserver using express-ws for reliable Websocket connection between my server and client browser. The code will start listening in port 3000 for websocket connection.

var express = require('express');
var app = express();
var expressWs = require('express-ws')(app);

app.use(function (req, res, next) {
req.testing = 'testing';
return next();

app.get('/', function(req, res, next){
console.log('get route', req.testing);
});'/', function(ws, req) {
ws.on('message', function(msg) {
console.log('socket', req.testing);


what is the use of next() API in express-websocket?

Answer Source

It calls the next middleware in the stack. Explained Here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download