Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:50:52+00:00 2026-06-13T20:50:52+00:00

I use node.js and express. I saved on the ‘ req.session ‘ a complex

  • 0

I use node.js and express.

I saved on the ‘req.session‘ a complex object that includes array of objects.
In addition I save reference to one of the objects in the array.
For example:

var value = {
    name: "name"
    , values: []
};

req.session.value = value;

//
// I populate 'req.session.value' with values (with the same structure)
//

// then I save reference to one of the inner objects

var currentValue = req.session.value[3];

//
// later I try to change the save object
//

currentValue.name = "newName";

I expected that if I change the ‘currentValue‘ then the ‘req.session.value[3]‘ will be changed as well. However, for some reason it doesn’t happen.

To be concrete, if I change the currentValue immediately after I assign it then the req.session.value[3] is changed but if I am doing it in the next call then just the currentValue is changed.

In the example: I do the assignments to the ‘req.session‘ in the “app.get(...)” if I change the value of the currentValue in the “app.get(...)” it is run ok (the value change in both places) but if I change it in the ‘app.post(...)‘ the only object that change is the currentValue while the req.session.value[3] left the same.

Thanks in advance,
Shai

The code:

'app.get("/template/:templateid/feature/add", isTemplate, function(req, res) {'
'    if (!req.session.features) { // if features empty'
''
'    // Save the first features level from the current template in the session '
'    req.session.features = req.session.template.feature;'
'    //'
'    if (!req.session.featureNodes) { // featureNotes is a stack/branch of the features'
'        req.session.featureNodes = [];'
'    }'
'    if (!req.query.featureroot || req.query.featureroot == "") {'
'    } else {'
'        var featureRoot = getFeature(req.query.featureroot, req.session.features); // get one object from req.session.features'
'        if (featureRoot) {'
'            req.session.featureNodes.push(featureRoot);     // save reference'
'            var featureR = req.session.featureNodes.pop();  // do check that work!'
'            var values = {'
'                name: "req.body.name"'
'                , description: "req.body.description"'
'                , wieght: "req.body.wieght"'
'                , created: new Date()'
'                , modified: new Date()'
'                , feature: []'
'            };'
''
'            featureR.feature.push(values); // also req.session.features changed'
'            req.session.featureNodes.push(featureRoot); // push the reference back for use later'
'        }      '
'    }'
'    res.render("addfeature2template.jade", { '
'        title: "Add new feature"'
'        ,template: req.session.template'
'        ,feature: req.session.featureNodes'
'    });'
'});'
''
'app.post("/feature/add", isUser, function(req, res) {'
'    var SUBMIT = "Create";'
'    var CANCEL = "Cancel";'
'    switch ( req.param("feature") ) {'
'        case SUBMIT:'
'            var fields = {  name: 1, description: 1, wieght: 1};'
'            var values = {'
'                name: req.body.name'
'                , description: req.body.description'
'                , wieght: req.body.wieght'
'                , created: new Date()'
'                , modified: new Date()'
'                , feature: []'
'            };'
'            if (req.session.featureNodes.length < 1) {'
'                req.session.features.push(values);'
'            } else {'
'                var featureRoot = req.session.featureNodes.pop(); // pop the reference'
'                featureRoot.feature.push(values);                 // change the object but the req.session.features didnt changed '
'            }'
'            req.session.template = template;'
'            res.redirect("/template/" + req.body.templateid);'
'        break;'
'        case CANCEL:'
'            res.redirect("/template/" + req.body.templateid);'
'            break;'
'    }'
'});'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:50:53+00:00Added an answer on June 13, 2026 at 8:50 pm

    req.session object is serialized (to store) between the requests.

    Example:

    Request 1:

    req.session = {};
    var a = { hello : 'world' };
    var b = a;
    req.session.a = a;
    req.session.b = b;
    

    In this context variables a, b, req.session.a, req.session.b points to one object. You can change field hello in any of these objects, and this will to change in each of them.

    After end of request req.session object will be serialized for session storage (memcached, mongodb, etc).

    Request 2:

    Before request 2 req.session object will be deserialized from storage. Now it contains plain values without references. You can access req.session.a and req.session.b but now it two different objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it safe to do something like this in Node.js/Express.js? // use Object.create(null) so
I use node.js and express, socket.io. I use session in Express. How can I
I use node.js and socket.io. I have an application that runs on the IP
How do I use XPath in Vala on a Xml.Node object? The only examples
I have a standard node.js static file server that I want to use to
With the following enabled: app.use(express.session({ store: sessionStore, secret: 'secret', key: 'express.sid'})); Whilst testing my
In my app (node / express / redis), I use some code to update
I am playing with the node-express-boilerplate project and trying to convert it to use
So far I've been able to successfully use node.js, express, and knox to add/update/delete/retrieve
I am trying to use neo4j database with Express (node.js). I've been looking for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.