express

Express - better pattern for passing data between middleware functions

一笑奈何 提交于 2020-02-27 07:09:43
问题 I just brought up this issue with Express and I am interested in what StackOverflow thinks about it: https://github.com/strongloop/express/issues/2831 my question is why Express opts to disallow the developer from passing data directly between middleware functions and basically forces you to assign temporary data to the request object in what I have always considered to be a quite awkward assignment. to be more specific: passing data between middleware functions usually involves doing this

Multiple Consumption of single stream

杀马特。学长 韩版系。学妹 提交于 2020-02-26 12:08:26
问题 I want to know if its possible that multiple functions can consume single stream in node.js. If yes How can this done? Is it possible to pipe to multiple destinations? I want to use the stream in two different functions which are parallel. I am doing the parallel flow using the async module. So will it possible to say issue the pipe() statement inside each of these functions? Thanks in advance. 回答1: Yes , it's possible, easy and common. The following is a piped data stream from a single

Expressjs secure session cookie

戏子无情 提交于 2020-02-26 09:14:45
问题 I cant seem to find a way to set a secure cookie in expressjs framework. Is there an option to do this somewhere? 回答1: Based on the documentation, try this: res.cookie('rememberme', 'yes', { expires: new Date(Date.now() + 900000), httpOnly: true, secure: true }); Using res.cookie(name, val[, options]) sets the given cookie name to val , with options httpOnly , secure , expires , etc. The path option defaults to the app’s basepath setting, which is typically "/" . See the docs for res.cookie

Firebase hosting and cloud functions don't work with formidable: incomingForm is not a constructor

戏子无情 提交于 2020-02-26 03:41:05
问题 I use express to handle post requests and formidable to parse uploaded files: import * as admin from "firebase-admin"; import * as functions from "firebase-functions"; import * as formidable from "formidable"; import * as util from "util"; import * as express from "express"; admin.initializeApp(); const app = express(); app.post("/image", (req, res) => { const form = new formidable.incomingForm(); form.parse(req, async function(err, fields, files) { res.writeHead(200, { "content-type": "text

Firebase hosting and cloud functions don't work with formidable: incomingForm is not a constructor

拜拜、爱过 提交于 2020-02-26 03:41:04
问题 I use express to handle post requests and formidable to parse uploaded files: import * as admin from "firebase-admin"; import * as functions from "firebase-functions"; import * as formidable from "formidable"; import * as util from "util"; import * as express from "express"; admin.initializeApp(); const app = express(); app.post("/image", (req, res) => { const form = new formidable.incomingForm(); form.parse(req, async function(err, fields, files) { res.writeHead(200, { "content-type": "text

401 Unauthorized Response On Post

柔情痞子 提交于 2020-02-25 23:37:32
问题 I've been making node.js website using angular template. But I can't create data on DB(Mongo). Here are code. node routing. var Property = mongoose.model('Property'); var jwt = require('express-jwt'); var auth = jwt({ secret: 'SECRET', userProperty: 'payload' }); var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId; //Have also tried Schema.Types.ObjectId, mongoose.ObjectId // Property Routing Management router.post('/property', auth, function(req, res, next) { var property = new

Why does using mongoose callback result in saving data twice?

谁说胖子不能爱 提交于 2020-02-25 13:29:05
问题 I have been wondering why adding a callback to the mongoose findOneAndUpdate function results in saving the data twice to the DB? public async addPersonAsFavorite(userId: string, friendId: string) { if (!await this.isPersonAlreadyFriend(userId, friendId)) { const friendList = FriendsList.findOneAndUpdate( { _id: userId }, { $push: { friendsList: friendId } }, { upsert: true, new: true }, (err, data) => { if (err) console.error(err); return data; } ); return friendList; }} public async

Parse numbers from query strings with bodyParser.urlencoded() in express.js

走远了吗. 提交于 2020-02-25 09:39:52
问题 In the front end, I use jQuery to send a GET request like this: $.get('/api', {foo:123, bar:'123'), callback); according to jQuery doc, the 2nd parameter is a plain object that will be converted into query string of the GET request. In my node express back end, I use body-parser like this: const bodyParser = require("body-parser"); app.use(bodyParser.urlencoded({ extended: true })); app.get('/api', (req, res) => { console.log(req.query) // req.query should be the {foo:123, bar:'123'} I sent }

Having issues pulling data from my database and populating it (ById) onto the my Vue view (using Axios). Backend is Node/Express

旧街凉风 提交于 2020-02-25 09:13:27
问题 I know by the console that the route is pointing it to the correct Id number, but it's throwing a 404 and I'm not sure where the connection is going bad. "PrizesById" is essentially a duplicate of another route holding data called "Prizes." I wasn't sure if recreating two separate places to pull identical data would be a way to do this, as I couldn't find a way to do it for "prizes". Both are required the same way This is a sample of my prizesbyid.js (in routes) const express = require(

Nodemailer got error: 'ECONNRESET' Code:'ESOCKET'

荒凉一梦 提交于 2020-02-25 06:20:45
问题 I tried to send mail using Nodemailer by using my mail server. It work fine in localhost:8000 buy when I deploy my project to production mode It's got error: 'ECONNRESET' fyi: I use express for the backend and deploy this project on window server 2012 This is an error error cannot sendmail: Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:201:27) { errno: 'ECONNRESET', code: 'ESOCKET', syscall: 'read', command: 'CONN' Here is the code const nodemailer = require(