Tutorial by Examples

If you are new to middleware in Express check out the Overview in the Remarks section. First, we are going to setup a simple Hello World app that will be referenced and added to during the examples. var express = require('express'); var app = express(); app.get('/', function(req, res) { r...
Let's create middleware that adds a property called requestTime to the request object. var requestTime = function (req, res, next) { req.requestTime = Date.now(); next(); }; Now let's modify the logging function from the previous example to utilize the requestTime middleware. myLogge...
This example demonstrates how a cross origin http request can be handled using a middleware. CORS Background CORS is an access control method adopted by all major browsers to avert Cross Scripting Vulnerabilities inherent by them. In general browser security, scripts should maintain that all XHR r...

Page 1 of 1