express-4

Socket.io connection keep increasing each time a new connect has been made

故事扮演 提交于 2021-01-28 07:41:28
问题 I'm using Express4 with a router that points to path / , and that is handled by a JS file named chat.js . And my IO object is already bind to app.io , so inside my chat.js I'll call my Socket.IO by using req.app.io , but the problem is, I use to be using socket.emit and the code just work fine, but now if I want to sync up with the client I have to using req.app.io.emit . And since because I'm using req.app.io.emit , I have the connection keep increasing problem. index.js const express =

Check if redis is running -> node js

狂风中的少年 提交于 2021-01-20 18:11:50
问题 I just wanted to know, at the beginning of my NodeJS process, if Redis is started or not (so users session will be stored or not). Here is what I have for the moment : var session = require('express-session'); var RedisStore = require('connect-redis')(session); var redis = require("redis"); var client = redis.createClient(global.redis.host, global.redis.port); // Check if redis is running var redisIsReady = false; client.on('error', function(err) { redisIsReady = false; console.log('redis is

Check if redis is running -> node js

萝らか妹 提交于 2021-01-20 18:11:26
问题 I just wanted to know, at the beginning of my NodeJS process, if Redis is started or not (so users session will be stored or not). Here is what I have for the moment : var session = require('express-session'); var RedisStore = require('connect-redis')(session); var redis = require("redis"); var client = redis.createClient(global.redis.host, global.redis.port); // Check if redis is running var redisIsReady = false; client.on('error', function(err) { redisIsReady = false; console.log('redis is

Include a module for all routes at express.js 4

时光怂恿深爱的人放手 提交于 2020-01-24 10:59:07
问题 I'm using Express 4.2.0 Is it possible to include a module only once in app.js and use it in any defined route? Right now this won't work: app.js //.. var request = require('request'); var routes = require('./routes/index'); var users = require('./routes/users'); app.use('/', routes); app.use('/users', users); //... routes/user.js var express = require('express'); var router = express.Router(); router.get('/add', function(req, res) { var session = req.session; request('http://localhost:8181

Forever Node.JS Express 4

自古美人都是妖i 提交于 2020-01-10 07:18:56
问题 How do you run the Express 4 app with Forever? (or is there a new package?) I am running my Express 3 apps with Forever installed locally with the package manager. I use the command: forever -a start app.js 回答1: Try this: forever start ./bin/www Let's take a look to package.json : "scripts": { "start": "node ./bin/www" }, I guess when we call npm start , ./bin/www will be executed at some point. Then look at the content of ./bin/www : var server = app.listen(app.get('port'), function() {

Forever Node.JS Express 4

无人久伴 提交于 2020-01-10 07:18:22
问题 How do you run the Express 4 app with Forever? (or is there a new package?) I am running my Express 3 apps with Forever installed locally with the package manager. I use the command: forever -a start app.js 回答1: Try this: forever start ./bin/www Let's take a look to package.json : "scripts": { "start": "node ./bin/www" }, I guess when we call npm start , ./bin/www will be executed at some point. Then look at the content of ./bin/www : var server = app.listen(app.get('port'), function() {

Express is listening on port 3000 despite setting it to 80?

﹥>﹥吖頭↗ 提交于 2020-01-06 20:21:39
问题 Running on Amazon EC2. The code was created automatically by express-generator. To start the app I had to do this: sudo PORT=80 npm start Then I added lines 14: app.set('port', process.env.PORT || 80); And 66 http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); Now I can start the app by saying: sudo npm start but it says - Express server listening on port 3000. I can access it from my browser, but why 3000 http:/

Node.js use csurf conditionally with express 4

与世无争的帅哥 提交于 2020-01-01 05:24:11
问题 I try to use csurf on just a few routes in my express app. that's the approach: var express = require('express'); var session = require('express-session'); var csrf = require('csurf'); // some more stuff var csrfExclusion = ['/myApi','/unsecure']; var app = express(); var conditionalCSRF = function (req, res, next) { if (csrfExclusion.indexOf(req.path) !== -1){ next(); } else{ csrf(); } }); app.use(conditionalCSRF); even tried: var conditionalCSRF = function (req, res, next) { if

Elasticsearch show all results using scroll in node js

若如初见. 提交于 2019-12-20 10:40:01
问题 I am basically trying to show all records of an index type. Now, if you use match_all() in query elasticsearch shows 10 results by default. One can show all results using scroll. I am trying to implement scroll api, but can't get it to work. It is showing only 10 results, my code: module.exports.searchAll = function (searchData, callback) { client.search({ index: 'test', type: 'records', scroll: '10s', //search_type: 'scan', //if I use search_type then it requires size otherwise it shows 0

Express4.10 bodyParser req.body undefined

南笙酒味 提交于 2019-12-11 11:15:41
问题 I'm trying to build the login of a node application trying to access the route / login get: req.body undefined Error: TypeError: Cannot read property 'usuario' of undefined at login (/home/makros/workspace/ntalk/controllers/home.js:8:24) at Layer.handle [as handle_request] (/home/makros/workspace/ntalk/node_modules/express/lib/router/layer.js:82:5) at next (/home/makros/workspace/ntalk/node_modules/express/lib/router/route.js:100:13) at Route.dispatch (/home/makros/workspace/ntalk/node