Skip to content

Instantly share code, notes, and snippets.

@pnhoang
Created April 16, 2017 21:24
Show Gist options
  • Save pnhoang/dae226aa5353c92d184232ed365e3a6e to your computer and use it in GitHub Desktop.
Save pnhoang/dae226aa5353c92d184232ed365e3a6e to your computer and use it in GitHub Desktop.
node.js express session secret
How I use sessions:
.env file (always in my .gitignore file so it never hits my public repos):
SECRET="This is my funky secret oh my god it has ninja turtles"
app.js:
var express = require('express'),
env = (function(){
var Habitat = require("habitat");
Habitat.load();
return new Habitat();
}()),
app = express();
app.use(express.compress()); // gzip all the things. If possible.
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.cookieSession({
key: "mysite.sid",
// seeing this tells you nothing about the actual secret:
secret: env.get("SESSION_SECRET"),
cookie: {
maxAge: 2678400000 // 31 days
}
}));
app.use(express.csrf());
http://stackoverflow.com/questions/18565512/importance-of-session-secret-key-in-express-web-framework
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment