express

Unhandled Promise Rejection Error in node js

微笑、不失礼 提交于 2020-12-15 06:08:57
问题 am getting error while executing combined queries Am using, sequelize and mysql Here is my code: const makeAuthenticate = async (req, res) => { const newOtp = Math.floor(100000 + Math.random() * 900000); try { const {phone} = req.body; const [user, created] = await db.User.findOrCreate({ where: { phone: phone }, }) .then(e => { db.User.update({ otp: newOtp }, { where: { phone: phone }}) .then(f => res.status(200).json({ otp: newOtp })) .catch(err => res.status(500).json({error: err})) //

What are your ways of securing a Express.js REST API?

China☆狼群 提交于 2020-12-15 05:16:12
问题 I'm building an app with an Express.js REST API as the back-end and I'm trying to wrap my head around all the necessary security measures and which libraries and tools to use. Could you guys and gals make a rundown of what your favorite and secure libraries you use for each part of the securing process are? Maybe also write why you use the ones you use. It would really help me a lot. Thank you in advance. 回答1: You should use CORS to prevent access to your API from unwanted origins (domain,

CORS anywhere returning proxy text, not desired target resource

亡梦爱人 提交于 2020-12-15 05:01:47
问题 I am trying to set up a proxy using node, express, and an instance of cors-anywhere for my arcgis-js-api app. My server file looks like this: import express from 'express'; import cors from 'cors'; import corsAnywhere from 'cors-anywhere'; const { PORT } = process.env; const port = PORT || 3030; var app = express(); let proxy = corsAnywhere.createServer({ originWhitelist: [], // Allow all origins requireHeaders: [], // Do not require any headers. removeHeaders: [], // Do not remove any

Why does the console.log appear twice in app.js in nodejs

我的未来我决定 提交于 2020-12-14 06:26:08
问题 I have written a code in NodeJS where when i hit the url, i need the server to pass through three middleware functions authentication, cookies, logging. Here it happens , but the console gets printed twice. Can you help me figure out why. var express = require('express'); var app = express(); var router = require('express').Router(); /* Add the middleware to express app */ app.use (function authentication(req,res,next){ if(req.method === 'GET'){ console.log("Inside Authentication.js") next();

Why does the console.log appear twice in app.js in nodejs

夙愿已清 提交于 2020-12-14 06:26:03
问题 I have written a code in NodeJS where when i hit the url, i need the server to pass through three middleware functions authentication, cookies, logging. Here it happens , but the console gets printed twice. Can you help me figure out why. var express = require('express'); var app = express(); var router = require('express').Router(); /* Add the middleware to express app */ app.use (function authentication(req,res,next){ if(req.method === 'GET'){ console.log("Inside Authentication.js") next();

Express node js webssockets is recieving messages from websocket server but not being able to send them

故事扮演 提交于 2020-12-13 05:41:14
问题 I have websockets setup with aws api gateway, I also have an ec2 instance running with node and express and ws websockets, I am able to send a message with wscat to the apigateway wss url and it shows up in the ec2 instance, but if I send a message from the ec2 instance it doesnt show up back in the wscat. I followed this tut to setup the apigateway https://aws.amazon.com/blogs/compute/announcing-websocket-apis-in-amazon-api-gateway/ Here is the ec2 instance code. I am not quite sure what

Express node js webssockets is recieving messages from websocket server but not being able to send them

社会主义新天地 提交于 2020-12-13 05:40:36
问题 I have websockets setup with aws api gateway, I also have an ec2 instance running with node and express and ws websockets, I am able to send a message with wscat to the apigateway wss url and it shows up in the ec2 instance, but if I send a message from the ec2 instance it doesnt show up back in the wscat. I followed this tut to setup the apigateway https://aws.amazon.com/blogs/compute/announcing-websocket-apis-in-amazon-api-gateway/ Here is the ec2 instance code. I am not quite sure what

Error: Cannot find module 'express' when running on Azure

让人想犯罪 __ 提交于 2020-12-13 04:32:27
问题 I have a node.js app which uses express and runs locally with no problems. However, on Azure I am seeing: Application has thrown an uncaught exception and is terminated: Error: Cannot find module 'express' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (D:\home\site\wwwroot\server.js:1:79) at Module._compile (module.js:570:32) at Object.Module.

Can't setup swagger - Cannot read property 'parameters' of undefined

陌路散爱 提交于 2020-12-13 04:12:33
问题 I am having a problem with setting up the swagger into my node.js application. I am using swagger-jsdoc and swagger-ui-express for creating documentation. Here are the versions "swagger-jsdoc": "3.5.0", "swagger-ui-express": "4.1.3" Below is the configs, which I pass to swagger-jsdoc. openapi: 3.0.0 info: description: test version: 3.0.0 title: U-CRM api documentation termsOfService: http://swagger.io/terms/ servers: - url: 'https://localhost:5000' description: Local server tags: - name: U

Redirect from HTTP to HTTPS using node.js/Express

余生颓废 提交于 2020-12-13 04:11:31
问题 Is there any way I can change my web app to listen on HTTPS instead of HTTP. I'm using node.js/express. I need it to listen on HTTPS because I'm using geolocation, which Chrome no longer supports unless being served from a secure context such as HTTPS. This is the current './bin/www' file which currently listens on HTTP. #!/usr/bin/env node var app = require('../app'); var debug = require('debug')('myapp:server'); var http = require('http'); var port = normalizePort(process.env.PORT || '9494'