Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've seen several posts related to this but none solved my problem.

I have this code in server.js

var express = require('express');
var app = express();
app.configure(function(){
    app.set(express.cookieParser());
        app.set(express.session({secret: "This is a secret"}));
});
app.get('/name/:name', function(req, res){
    req.session.name = req.params.name;
    res.send("<a href='/name'>GO</a>");
});
app.get('/name', function(req, res){
    res.send(req.session.name);
});
app.listen(3000);

When I go to http://localhost:3000/user/someone that's the output that I get TypeError: Cannot set property 'name' of undefined at /Users/Me/Node/server.js:10:19 at callbacks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
326 views
Welcome To Ask or Share your Answers For Others

1 Answer

Decided to copy from comments. Try replacing

app.configure(function(){
    app.set(express.cookieParser());
        app.set(express.session({secret: "This is a secret"}));
});

with

app.use(express.cookieParser());
app.use(express.session({secret: "This is a secret"}));

and see what happens.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...