express

nodejs formidable not triggering any events

孤街浪徒 提交于 2020-01-13 09:44:33
问题 I am on express3.x and using formidable app.post "/up",(req,res)-> formidable = require('formidable') form = new formidable.IncomingForm() form.uploadDir = __dirname + "/uploads" form.encoding = 'binary' form.addListener 'file',(name,file) -> #write file console.log('file uploaded') return console.log('$$$$$$$$$$$') form.addListener 'end', -> console.log('end') res.end() return console.log('@@@@@$$$$') form.parse req,(err,fields,files)-> console.log('parse') console.log(err) if(err) return

Express.js multiple methods

为君一笑 提交于 2020-01-13 09:23:26
问题 So in Express you can do: app.get('/logo/:version/:name', function (req, res, next) { // Do something } and app.all('/logo/:version/:name', function (req, res) { // Do something } Is there a way to just have two methods (ie. GET and HEAD)? Such as: app.get.head('/logo/:version/:name', function (req, res, next) { // Do something } 回答1: Just pull out the anonymous function and give it a name: function myRouteHandler(req, res, next) { // Do something } app.get('/logo/:version/:name',

502 Bad Gateway error for my server running with Node JS on nginx proxy

南楼画角 提交于 2020-01-13 08:56:26
问题 I am getting 502 bad gateway error: when I check the nginx error log I find this: 2017/05/06 02:36:04 [error] 48176#0: *135 connect() failed (111: Connection refused) while connecting to upstream, client: 10.163.XX.X, server: abc-def-ghi, request: "GET /favicon.ico HTTP/1.1", upstream: "https://127.0.0.1:5300/favicon.ico", host: "hostnname", referrer: "hostname-1 I searched internet enough but could not find anything. One thing to note here is that, this intermittent error is coming only on a

Node.js / Express / Mocha / Supertest Rest API - Empty Request Body

房东的猫 提交于 2020-01-13 07:49:24
问题 I've looked everywhere I can to find a solution to this. The only thing I've found is an unanswered post. I apologize if I've overlooked something. The problem is that when I try to get the POST values in the /createQuestion API, the body is empty/undefined. I get errors like this Cannot read proprety 'question' of undefined coming from the API. The Express API: app.post("/createQuestion", function(req, res) { var questionType = req.body.question.type; var questionText = req.body.question

express global middleware not being called

≯℡__Kan透↙ 提交于 2020-01-13 07:39:09
问题 As far as I can tell I'm configuring my global middleware function as described in the docs and in every forum post on the subject, but it is not being called. Does anyone see what I'm doing wrong? express 3.2.5. In the log output I see the following: Express server listening on port 9000 inside route GET / 200 7ms - 2b I expect to see "inside middleware", then "inside route". Instead, I just see "inside route". The code: var express = require('express'), http=require('http'), path=require(

Basic auth with passport and express

冷暖自知 提交于 2020-01-13 06:50:22
问题 I must have missed something, but according to all the tutorials I've found, this is how you do basic auth with a node application using express and passport + passport-local . I know it's not according to best practice, I'm just trying to get a POC going: 'use strict' var express = require('express'); var passport = require('passport'); var LocalStrategy = require('passport-local').Strategy var app = express(); var users = { 'user': 'secretpass'}; passport.use(new LocalStrategy( function

Res.Render is not a function error in node.js

▼魔方 西西 提交于 2020-01-13 06:39:51
问题 I am getting an "res.render is not a function error" in the Windows 10 Command Prompt when I try to run my node.js code. What is causing this error and how can I get rid of it? Here is my .js file: /*eslint-env node*/ //------------------------------------------------------------------------------ // node.js starter application for Bluemix //------------------------------------------------------------------------------ // HTTP request - duas alternativas var http = require('http'); var

Json Web Token verify() return jwt malformed

本小妞迷上赌 提交于 2020-01-13 06:24:04
问题 const jwt = require("jsonwebtoken"); const SECRET = "superSuperSecret"; module.exports = function(req, res, next) { const token = req.body.token || req.query.token || req.headers[ "x-access-token" ]; if (token) { return jwt.verify(token, SECRET, function(err, decoded) { if (err) { return res.json({ success: false, message: "Failed to authenticate token.", }); } req.user = decoded; return next(); }); } return res.unauthorized(); }; I'm using Postman to test my API. I setup the header with a x

How do I return 304 Unmodified status with Express.js?

假如想象 提交于 2020-01-13 05:45:22
问题 I'm using node and express for the back end of an iOS application. Data is stored in a SQL Server database, so iOS apps query the server, the server queries the database, server receives the db response, and then forwards the response to the iOS application. I'm trying to figure out how caching works though. I'm serving a lot of static content - blog articles for example. So I planned to use etags, but I'm not sure how it's supposed to work. I make a request, get content, and cache the

Kerberos Authorization w/ Node.js

六月ゝ 毕业季﹏ 提交于 2020-01-13 05:30:14
问题 I have found many different node.js authentication modules. Ei passport-kerberos. But I am looking to make background https calls to another kerberos authenticated site w/ an authorization token. Does anyone know of any modules for getting an authorization token from credentials in a node app? 来源: https://stackoverflow.com/questions/22724978/kerberos-authorization-w-node-js