I am new to node.js and trying to create a small API. I am using Express for routing and async.jc for processing the Calls Step by Step. This works fine when only one Request comes in, but when i try to fire 2 or more requests from my Machine the process is mixing up values in variables and crashes.
Here is short snippet from my source:
router.get('/new', function (request, res) {
async.waterfall([
function(callback) {
// get a unique domain
client.spop('domainSet', function(err, domain) {
userdata = {
email: 'user' + '@' + domain + '.' + mydomain,
password: randomstring.generate(10),
username: domain,
name: domain,
confirm: "false"
}
if (err) return next(err);
callback(null, userdata, userdata.password);
})
},
function(userdata, userpwd, callback) {
myapp.users.create(userdata, function(user) {
console.log('Creating new user: ' + userdata.email);
callback(null, user, userpwd);
});
},
How is it possible to keep the "context/scope" per request? i am sure im missing something (-: Or is the only problem that i fire the request from the same Machine??
userdatain the first function is not declared anywhere, so it is getting global scope. tryvar userdata = {