Created
April 16, 2017 21:24
-
-
Save pnhoang/dae226aa5353c92d184232ed365e3a6e to your computer and use it in GitHub Desktop.
node.js express session secret
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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