anand
anand

Reputation: 11309

How nodejs can maintain a state of persistent connection

I am very new to nodejs and have few doubts regarding it.

With nodejs we can maintain a number of parallel connections. So it means multiple clients can simultaneously maintain connections to nodejs server. There can be authentication required on server side.I am not clear how these authentications and session data can be stored for multiple connections on nodejs server.

Upvotes: 1

Views: 2660

Answers (2)

Kfir Erez
Kfir Erez

Reputation: 3470

Hi Alien and welcome to node.js!

I recommend to use express and redis to store session information. Take a look at the following tutorial for better example.

In addition you can look for redis clients on node.js at the redis site here.

Regarding authentication; if you use simple authentication you can implement it by yourself however you can also use existing modules such as passport which is very simple and do the job well.

In general, I'm a veteran Java developer and for the right purposes (mainly web apps) I recommend node.js for its time to market and performance.

Upvotes: 3

user717166
user717166

Reputation: 680

You can use connect. http://www.senchalabs.org/connect/session.html

 connect()
.use(connect.favicon())
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
.use(function(req, res, next){
  var sess = req.session;
  // you can set your authentication script through the session here.

}

)).listen(3000);

Upvotes: 0

Related Questions