Nicola
Nicola

Reputation: 475

node.js global variable between different functions

I'm using Nodejs, Express and MongoDB for creating a web application. For the user registration I assign an ID to each user using a function called by the action (POST) of a form and I assign also a confirmation code (like "123456") for checking the identity of the user into another function called by the confirmation page that appear after the registration page. How can I get the user ID into the other function? (called after pressing submit into another form)

Do I have to use sessions? I think I don't know the right approach to these things

edit: I store the user data into a mongoDB database

Upvotes: 1

Views: 955

Answers (1)

Spork
Spork

Reputation: 1651

I would say you're thinking the right way, and just need a short guide to get to do it. Sessions are the way to go here, and although you could store those anywhere, I'd suggest you start with basic in-memory sessions for now.

I found the following guide helpful: http://blog.modulus.io/nodejs-and-express-sessions. Just take it as far as Redis and not further, and you'll be well on your way.

Upvotes: 1

Related Questions