Debugging your ExpressJS web application
Debugging information on ExpressJS about all of the cycle of a web application is something simple. ExpressJS uses the debug NPM module internally to log information. Unlike console.log
, debug logs can easily be disabled on production mode.
Getting ready
In this recipe, you will see how to debug your ExpressJS web application. Before you start, create a new package.json
file with the following content:
{ "dependencies": { "debug": "3.1.0", "express": "4.16.3" } }
Then, install the dependencies by opening a terminal and running:
npm install
How to do it...
- Create a new file named
debugging.js
- Initialize a new ExpressJS application:
const express = require('express') const app = express()
- Add a route method to handle
GET
requests for any path:
app.get('*', (request, response, next) => { response.send('Hello there!') })
- Listen on port
1337
for new connections:
app.listen( 1337...