express

Node JS: How to Promise For Loop

只愿长相守 提交于 2020-08-10 22:53:35
问题 I'm trying to create a NodeJS app. Below is code that is supposed to be called when an admin creates a new product. Most of the code works, but I'm having trouble rendering the view only after the rest of the code has executed (the DB functions are asynchronous). I've wrapped much of the code in promises (to make certain blocks execute in the right order) and console logs (to pinpoint problems). I'd like to point out that the console.dir(rejProducts) just below console.log(111) logs and empty

Socket double emits problem in express route (event handler stacking)

拟墨画扇 提交于 2020-08-10 19:37:27
问题 I have problem with stacking socket event handler when hitting express route. I need to reconnect in route then sending emit to specific room. At first I connect (socket.io) at page X, then connection is lost cause I move to page Y (with use of router.post) and then in router when I reconnect I add new global socket.io handler for the connection event... and cause of that emits are send multiple times. Ideally, I should use some kind of session to know that user disconnect/connect and be able

Socket double emits problem in express route (event handler stacking)

醉酒当歌 提交于 2020-08-10 19:36:35
问题 I have problem with stacking socket event handler when hitting express route. I need to reconnect in route then sending emit to specific room. At first I connect (socket.io) at page X, then connection is lost cause I move to page Y (with use of router.post) and then in router when I reconnect I add new global socket.io handler for the connection event... and cause of that emits are send multiple times. Ideally, I should use some kind of session to know that user disconnect/connect and be able

session handling in expressjs with router

China☆狼群 提交于 2020-08-10 04:35:52
问题 I'm using expressJS, and I'm a bit confused about sessions. I have 1 single expressJS server, which is reachable from different URLs. Depending on where the connection is coming frmo (which URL is opened), a different database is used to provide the responses. And I can see that the sessions are conflicting. My assumption is that I should be setting different cookie names, based on the URL of the request, but it seems I can't specify a function within the session config. Any ideas? var app =

Nodemon: Error: listen EADDRINUSE: address already in use :::5000

天大地大妈咪最大 提交于 2020-08-09 13:51:49
问题 I'm creating a project and using nodejs, express for the backend. Everything works fine but as I make any change in the file, nodemon is unable to restart the server due to following error: Error: listen EADDRINUSE: address already in use :::5000 index.js: const express = require("express"); const morgan = require("morgan"); const mongoose = require("mongoose"); const cookieParser = require("cookie-parser"); const session = require("express-session"); const FileStore = require("session-file

Nodemon: Error: listen EADDRINUSE: address already in use :::5000

心不动则不痛 提交于 2020-08-09 13:47:46
问题 I'm creating a project and using nodejs, express for the backend. Everything works fine but as I make any change in the file, nodemon is unable to restart the server due to following error: Error: listen EADDRINUSE: address already in use :::5000 index.js: const express = require("express"); const morgan = require("morgan"); const mongoose = require("mongoose"); const cookieParser = require("cookie-parser"); const session = require("express-session"); const FileStore = require("session-file

React/Node Uncaught SyntaxError: Unexpected token <

会有一股神秘感。 提交于 2020-08-09 09:26:28
问题 I've tried everything but I'm a bit lost on where I should look into this issue. What happens is that once you build the react app and deploy it (using node/express), it works perfectly. However, if you build again and take the build folder to the node server, it gives me that syntax error. This only happens if your browser already opened the app once. I've done research and people were saying that the browser is trying to load the older static files and that's why this occurs. None of their

Pass array of objects from route to route

元气小坏坏 提交于 2020-08-09 08:49:33
问题 I'm using Node.js and Express.js and I tried to pass an array of objects from route to other route. I tried to pass through QueryString, but the typeof says that it is an object and it doesn't work properly. I should either pass it to /contacts in another way somehow, or convert the result of the QueryString to an array of object and use it. Here is what I tried to do: app.get('/names', function(req, res) { var arr = new Array(); arr.push({name: 'John'}); arr.push({name: 'Dani'}); res

Pass array of objects from route to route

北城以北 提交于 2020-08-09 08:48:11
问题 I'm using Node.js and Express.js and I tried to pass an array of objects from route to other route. I tried to pass through QueryString, but the typeof says that it is an object and it doesn't work properly. I should either pass it to /contacts in another way somehow, or convert the result of the QueryString to an array of object and use it. Here is what I tried to do: app.get('/names', function(req, res) { var arr = new Array(); arr.push({name: 'John'}); arr.push({name: 'Dani'}); res

Cookies headers are present but Cookies are not stored in browser

人走茶凉 提交于 2020-08-09 07:00:38
问题 Please help me to figure out why the browser (Chrome and any others) does not set cookies, while Set-Cookie header is present in Response Headers: Access-Control-Allow-Origin: * Connection: keep-alive Content-Length: 345 Content-Type: application/json; charset=utf-8 Date: Sat, 18 Jan 2020 21:15:53 GMT ETag: W/"159-UXuykOchcveuYBb7xZpN5Luf3jU" Set-Cookie: jwt=************; Path=/; Expires=Fri, 17 Apr 2020 21:15:53 GMT; HttpOnly Strict-Transport-Security: max-age=15552000; includeSubDomains X