Automatic HTTPS connection/redirect with node.js/express

I’ve been trying to get HTTPS set up with a node.js project I’m working on. I’ve essentially followed the node.js documentation for this example: // curl -k https://localhost:8000/ var https = require(‘https’); var fs = require(‘fs’); var options = { key: fs.readFileSync(‘test/fixtures/keys/agent2-key.pem’), cert: fs.readFileSync(‘test/fixtures/keys/agent2-cert.pem’) }; https.createServer(options, function (req, res) { res.writeHead(200); res.end(“hello world\n”); }).listen(8000); Now, … Read more

How can I set cookie in node js using express framework?

In my application, I need to set a cookie using the express framework. I have tried the following code but it’s not setting the cookie. var express = require(‘express’), http = require(‘http’); var app = express(); app.configure(function(){ app.use(express.cookieParser()); app.use(express.static(__dirname + ‘/public’)); app.use(function (req, res) { var randomNumber=Math.random().toString(); randomNumber=randomNumber.substring(2,randomNumber.length); res.cookie(‘cokkieName’,randomNumber, { maxAge: 900000, httpOnly: true }) … Read more

How to specify HTTP error code using Express.js?

I have tried: app.get(“https://stackoverflow.com/”, function(req, res, next) { var e = new Error(‘error message’); e.status = 400; next(e); }); and: app.get(“https://stackoverflow.com/”, function(req, res, next) { res.statusCode = 400; var e = new Error(‘error message’); next(e); }); but always an error code of 500 is announced. 12 Answers 12