Skip to content

Instantly share code, notes, and snippets.

View longnt80's full-sized avatar

Long Nguyen longnt80

  • Melbourne, Australia
View GitHub Profile
@longnt80
longnt80 / basic_auth_nodejs_test.js
Created January 1, 2019 00:30 — forked from charlesdaniel/basic_auth_nodejs_test.js
Example of HTTP Basic Auth in NodeJS
var http = require('http');
var server = http.createServer(function(req, res) {
// console.log(req); // debug dump the request
// If they pass in a basic auth credential it'll be in a header called "Authorization" (note NodeJS lowercases the names of headers in its request object)
var auth = req.headers['authorization']; // auth is in base64(username:password) so we need to decode the base64
console.log("Authorization Header is: ", auth);