Wednesday 18 December 2019

javascript - nodejs express: store parameters in variable

I am still new with nodejs, still not sure how to access a variable in a function and call the variable back.



check few links: but im getting really confused. Please help!



Node.JS: How to pass variables to asynchronous callbacks?




How can we access variable from callback function in node.js?



var express = require('express');
var app = express();
var router = express.Router();
var https = require('https').createServer( ssl_options, app);
var io = require('socket.io')( https );
**var user_id;
var room_id;**


router.use(function(req, res, next) {
next();
});

app.use('/chat',router);

router.route( '/chat/:user_id/:room_id' )
.get(function(req,res){

res.sendFile( __dirname + '/index.html' );


user_id = req.param('user_id');
room_id = req.param('room_id');

});

https.listen(3000);

io.on('connection', function(socket){


**console.log ( user_id );
console.log ( room_id );**


});

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...