In my app.js file I have I am exporting an object with properties and values. On the route, I am including the file but I am getting the value as undefined. If I don't pass in the argument "users" in the createUser function it returns the value as undefined. If I pass in the argument, the server crashes and says it cannot get the .id of undefined. My goal is to have the value increment by 1 when the path is reached.
My app.js file:
exports.users = {
id : 1,
room : 0
};
var express = require('express');
var app = express();
var enter = require('./routes/enter');
var chat = require('./routes/chat');
var room = require('./routes/room');
var user = require('./routes/user');
var update = require('./routes/update');
app.use('/room', room);
app.use('/user', user);
app.use('/enter', enter);
app.use('/chat', chat);
app.use('/update', update);
app.use(express.static('public/dist'));
app.use(express.static('public/js'));
app.use(express.static('public/dist/images'));
app.use(express.static('bower_components'));
app.listen(1337);
My user file:
var express = require('express');
var user = express.Router();
var room = require('./room.js');
var users = require('../app.js').users;
user.get('/', function(req, res) {
createUser();
res.send(users.id.toString());
});
function createUser(){
users.id = users.id + 1;
console.log(user.id + ' this is the user.id');
return users;
}
module.exports = user;
I have an array that I want to transform into an object. For example: const arr = [{id: 1, key: ''}, {id: 2, key: ''}]; I want the result to be: const object = { 1: {id: 1, key: ''}, 2: { id: 2, ...
I have an array that I want to transform into an object. For example: const arr = [{id: 1, key: ''}, {id: 2, key: ''}]; I want the result to be: const object = { 1: {id: 1, key: ''}, 2: { id: 2, ...
I tried creating mixing in a getter into a JS object via the spread operator syntax, however it always seems to return null. HTML: <body> <div id="wrapperA"></div> <div id="...
I tried creating mixing in a getter into a JS object via the spread operator syntax, however it always seems to return null. HTML: <body> <div id="wrapperA"></div> <div id="...
I have an two elements fruits and crates fruits is an array containing a list of different fruits like: ["apple","orange","mango","pear"] crates is an array of objects which contains fruits in it ...
I have an two elements fruits and crates fruits is an array containing a list of different fruits like: ["apple","orange","mango","pear"] crates is an array of objects which contains fruits in it ...
How can I translate this curl script to an AJAX request in JavaScript? curl -X POST -d "grant_type=password&username=admin&password=Demo1234" -u "<ClientID>:<ClientSecret&...
How can I translate this curl script to an AJAX request in JavaScript? curl -X POST -d "grant_type=password&username=admin&password=Demo1234" -u "<ClientID>:<ClientSecret&...