O'Reilly logo

Node Web Development by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A quick look at authenticating your users

There are many application types where users log in to use privileged features. Since HTTP is a stateless protocol the only way to authenticate a user is by sending a cookie to their browser, after making them perform some action to verify their identity. The cookie would contain that data the application can use to verify the user. We're going to take a quick tour through implementing a login form, sending a cookie to the browser, and preventing access to Notes unless the cookie is present.

We start with a couple of modifications to app.js, the first of which is the server object configuration to add the cookieParser middleware:

var app = express.createServer();
app.use(express.logger());
app.use(express.cookieParser()); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required