Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Node Cookbook: Second Edition
  • Table Of Contents Toc
Node Cookbook: Second Edition

Node Cookbook: Second Edition

By : David Mark Clements
4.3 (7)
close
close
Node Cookbook: Second Edition

Node Cookbook: Second Edition

4.3 (7)
By: David Mark Clements

Overview of this book

Table of Contents (18 chapters)
close
close
Node Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1
Index

Initializing and using a session


If we want to maintain the state between page requests, we use sessions. Express supplies middleware that takes much of the complexity out of managing sessions. In this recipe, we're going to use Express to make a session between a browser and server to facilitate a user login process.

Getting ready

Let's create a fresh project:

express login

This will create a new Express skeleton named login.

Let's move into the login folder and run the following commands:

npm install [email protected] --save
npm install method-override @1.x --save

These are both pieces of Express middleware, which we'll use in our new login app.

How to do it...

We need to add some lines to app.js. First, where we require the dependencies, let's require express-session and method-override:

var express = require('express');
var http = require('http');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Node Cookbook: Second Edition
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon