Book Image

Mastering Web Application Development with Express

By : Alexandru Vladutu
Book Image

Mastering Web Application Development with Express

By: Alexandru Vladutu

Overview of this book

Table of Contents (18 chapters)
Mastering Web Application Development with Express
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the V8 debugger


V8 comes with a debugger that can be accessed from outside the process by using a TCP protocol. Node comes with a built-in client for the debugger, but we can also add external tools to connect to the debugger—such as node-inspector (https://www.npmjs.org/package/node-inspector).

Creating our buggy application

To showcase the debugger, we will create a sample Express application that contains a bug (not that hard to spot actually). The application will have three endpoints:

  • /: The main page will assign a random name and e-mail to the session in case they don't already exist, or redirect the user to /whoami if they are already set

  • /whoami: This is used to check the name and e-mail stored in the session

  • /refresh: This destroys the session and redirects to the main page

The code for this application is as follows:

var express = require('express');
var app = express();
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express...