NodeJS - Secrecy Required

I am new to working with nodejs and I'm just trying to start a server that is already working with my teammates. I am on mac and have already installed all the necessary modules with "npm install". Now, it seems the problem is with the cookie-signature module, which is already included in the express module. I try to run the program and I do not get an error, but when I try to open a page on localhost: 3000, I get the following error:

/Users/kevinglaap/Sites/Uni/git/node_server/node_modules/express/node_modules/cookie-signature/index.js:19 if ('string' != typeof secret) throw new TypeError('secret required'); ^ TypeError: secret required at Object.exports.sign (/Users/kevinglaap/Sites/Uni/git/node_server/node_modules/express/node_modules/cookie-signature/index.js:19:40) at ServerResponse.end (/Users/kevinglaap/Sites/Uni/git/node_server/node_modules/express/node_modules/connect/lib/middleware/session.js:267:34) at ServerResponse.EventEmitter.emit (events.js:93:17) at ServerResponse.res.writeHead (/Users/kevinglaap/Sites/Uni/git/node_server/node_modules/express/node_modules/connect/lib/patch.js:73:36) at ServerResponse._implicitHeader (http.js:932:8) at ServerResponse.OutgoingMessage.end (http.js:767:10) at res.end (/Users/kevinglaap/Sites/Uni/git/node_server/node_modules/express/node_modules/connect/lib/middleware/session.js:282:13) at /Users/kevinglaap/Sites/Uni/git/node_server/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:73:11 at process.startup.processNextTick.process._tickCallback (node.js:244:9) 

The module is never used in server resources. I already tested the use of the "sign" function, because an error is a fixed error that signals that resources may be doing something wrong, but it is only used by express or other modules inside express. Iโ€™ve searched the Internet for several days and havenโ€™t yet found a solution. What am I missing? Thanks in advance for your help.

+6
source share
2 answers

When setting up your express instance, you will need the following:

 app.use(express.cookieParser('your secret here')); app.use(express.session()); 

Make sure your cookieParser (with your secret string) is before express.session()

+11
source

with updated express version:

 var app = express(); app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true })); 
0
source

All Articles