Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS - Error secret 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 a mac and already installed all the needed modules with "npm install". Now there seems to be a problem with the module "cookie-signature", which is already included in the "express"-module. I am trying to start the program and i get no error, but when i try to open the 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 the server resources. I already checked for the usage of the "sign"-function, because the error is a fetched error, which signals that the resources may be doing something wrong, but it is only used by express or other modules within express. I have been searching the web for days now and haven't found a solution yet. What am i missing? Thanks in advance for your help.

like image 895
Kevin Glaap Avatar asked Dec 14 '12 11:12

Kevin Glaap


1 Answers

When configuring your express instance your need this:

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

Making sure your cookieParser (with your secret String) is before the express.session()

like image 141
Ben Evans Avatar answered Oct 03 '22 09:10

Ben Evans