express

Cannot Connect to MongDB Atlas using Mongoose

荒凉一梦 提交于 2020-01-03 04:16:50
问题 I am starting to learn a MERN stack tutorial. I initially created a react app, added a directory called backend, installed express, cors, express, and dotenv, then created a server.js and added some code, but after connecting to mongodb atlas, I get the error below: (node:5828) UnhandledPromiseRejectionWarning: MongoTimeoutError: Server selection timed out after 30000 ms at Timeout. (C:\Users\Lenovo\Desktop\REACTion\mernapp\backend\node_modules\mongodb\lib\core\sdam\topology.js:878:9) at

node.js - Passport not persisting across browser requests, works with Postman

倖福魔咒の 提交于 2020-01-03 03:38:06
问题 I am currently using the create-react-app boiler plate and have been attempting to add auth. I am using axios as my promise based HTTP libray with React.js. I have been using node with express, express-session, passport and passport-local on the backend. Here is my server.js file with some exlusions: const express = require('express'); const mysql = require('mysql'); const app = express(); const cors = require('cors'); const session = require('express-session'); const passport = require(

Memory leak in express.js api application

心不动则不痛 提交于 2020-01-03 03:23:07
问题 I am running an express.js application, which is used as a REST api. One endpoint starts puppeteer and test my website with several procedures. After starting the application and the continuous consumption of the endpoint, my docker container runs out of memory every hour as you can see below. First, I thought I have a memory leak in my puppeteer / headless chrome, but I then I monitored the memory usage from the processes, there isn't and memory leak visible as you can see here: 0.00 Mb

`Confirm Form Resubmission` issue on page rendered thru app.post('/', in expressjs

偶尔善良 提交于 2020-01-03 03:09:04
问题 html contains form(name="Form", action="/", method="post") button(type='submit') submit Express server contains: app.post('/', function(req, res){ res.render('home', {user: req.body}); }); As expected the home.jade is rendered in the browser. But when I refresh the home.jade file at http://localhost:3000 It asks for Confirm Form Resubmission I want to get rid of this - Confirm Form Resubmission ! The home.jade file is simple file containing simple text. 回答1: The problem isn't really caused by

How to render template in route with params in Express?

倾然丶 夕夏残阳落幕 提交于 2020-01-03 02:55:30
问题 I am using Express and Pug template engine. I have two routes: /profile which shows logged in user profile info. Can be accessed only by logged in users /profile/:id which shows other user's info. Can be accessed by everyone. Here is my code: app.get("/profile/:id", function(req,res) { // Get info from DB for specifed username in req.params.id res.render("profile.pug", locals); }); app.get("/profile", isLoggedIn, function(req,res) { // isLoggedIn is middleware which checks if user is logged

Exclude public folder from Express router

你说的曾经没有我的故事 提交于 2020-01-03 02:31:29
问题 I want to exclude the public folder and all static files and subfolders from express router. Currently I have defined 1) the public folder, 2) the router as suggested in several SF answers: // public folder self.app.use(express.static(path.join(__dirname, 'public'))); // static pages self._options.staticRoutes.forEach(route => { self.app.use(BASEPATH + route, express.static(path.join(__dirname, 'public'))); }); // register page renderer router.get(BASEPATH, renderer.render()); // templates

Why can't different servers bind to the same port?

谁都会走 提交于 2020-01-02 20:18:22
问题 I am confused about ports. I find it odd that we need to bind different servers to different ports. Example: Apache binded on 8080, Express.js can't bind on 8080 How does server port binding differ from application port listening? Example: Different browsers, ie, chrome, firefox, can listening and communicated on port 80? This issue came up when trying to run "grunt test:unit". There was a tomcat server that was already bound to 8080, but the server grunt starts, middleware I believe, is able

Node Express and csurf - 403 (Forbidden) invalid csrf token

只愿长相守 提交于 2020-01-02 17:21:34
问题 Looked through and tried everything I could find on here, and elsewhere by Googling...and I'm just not able to get past this. I'm using Node, Express, EJS, and attempting to use csurf on a form, that is posted w/ jQuery ajax. No matter how I configure csurf, I get "403 (Forbidden) invalid csrf token" I've tried configuring both globally in app.js and in the controller. Here's what I tried in app.js: var express = require('express'); var session = require('express-session'); var path = require

sails.js Getting a POST payload with text/plain content type

♀尐吖头ヾ 提交于 2020-01-02 16:06:07
问题 I'm developing a sails.js (node.js framework based on express) aplication, which is going great but ]I can't solve this detail... I need to send POST requests cross domain from internet explorer 8 and 9. For that I'm forced to use xDomainRequest object, wich doesn't allow to set a Content type header. So, when the request gets to the server the content type is "text/plain", which doesn't fire the bodyParser express middleware, so my req.body is an empty object and I can't see the payload I'm

Switch database in a connection pool in nodejs MySQL

僤鯓⒐⒋嵵緔 提交于 2020-01-02 13:27:49
问题 How can I switch the database after connecting to MySQL in nodejs using connection pool? I used to use the normal connection with MySQL since it has some issue now I would like to use the connection pooling. But how can I change the database after creating a connection with MySQL? Here is how I change the database: conn.changeUser({ database: req.session.dbname }, function (err) { if (err) { console.log(err); } else { next(); } }); But now it shows conn.changeUser is not a function Here is