express

ExpressJS Multer: Upload image to server

我怕爱的太早我们不能终老 提交于 2020-01-04 19:47:23
问题 I'm newer with Node.js and Express.js. I want to upload first a image into the server (directory: uploads/spots), and then (synchronous) upload the rest of form data in MongoDB. I'm using REST (Method Post) app.route('/spots').post(users.requiresLogin, spots.create); and I'm using Multer for updating the image into the server, and works. app.use(multer( { dest: './public/uploads/spots', onFileUploadStart: function (file) { var imagePath = file.path; gm(imagePath).resize(850, 850).quality(70)

Unit test express route calls controller method?

元气小坏坏 提交于 2020-01-04 16:59:11
问题 I see some similar questions, but my setup is slightly different and I can't figure out a good way to test this. I'm trying to test that my express app routes are directed to the correct controller methods. For example - //server.js, base application var express = require("express"); var app = express(); require("./routes.js")(app); ... //routes.js var menuController = require("./controllers/menu.js"); module.exports = function(expressApp) { expressApp.get('/menu', menuController.getMenu); };

Get SESSIONID in nodeJS

为君一笑 提交于 2020-01-04 14:31:31
问题 Now, after some hours of playing around with nodejs and socket.io, I'm getting a couple more problems - one being, that I need to get the sessionID inside node.js, whitout using app.get('/' ... - since that event doesnt seem to fire when socket.io connects, it only fires .on('connection', function( ... var express = require('express')() express.set('port', process.env.PORT || 8080) var server = require('http').createServer(express) var socket = require('socket.io').listen(server) server

Finding a MongoDB document through a word in a field description in each product with Mongoskin

老子叫甜甜 提交于 2020-01-04 13:37:57
问题 This is an example of document that I have in my MongoDB: { "_id": ObjectId('5525039895884d66710d0fc3'), "prid": "63527", "data": { "sku": "HF22-81639", "name": "Product Test", "ean": "8763900872512", "description": "This product is my first test", } } This search for "description" does not work (this is where I need help): app.get("/description/:id", auth, function(req, res, next) { req.collection.findOne({ "data.description": req.params.id }, function(e, result) { if(e) return next(e); res

Finding a MongoDB document through a word in a field description in each product with Mongoskin

。_饼干妹妹 提交于 2020-01-04 13:37:19
问题 This is an example of document that I have in my MongoDB: { "_id": ObjectId('5525039895884d66710d0fc3'), "prid": "63527", "data": { "sku": "HF22-81639", "name": "Product Test", "ean": "8763900872512", "description": "This product is my first test", } } This search for "description" does not work (this is where I need help): app.get("/description/:id", auth, function(req, res, next) { req.collection.findOne({ "data.description": req.params.id }, function(e, result) { if(e) return next(e); res

Mongoose find() call inside for loop using a latch

人盡茶涼 提交于 2020-01-04 13:27:54
问题 I've been on this for hours and can't seem to find the answer. The problem is that I have a call to a mongoDB inside a for loop. I'm using a latch so the for waits for the call to end before advancing again. Here's my code: var latch = true; for (var i=0; i<array.length; i++) { while(latch == false){} Table1.find({}, function(err, result){ ... some code ... latch = true; }); latch = false; } The problem is that it doesn't even run the callback from Table1.find(), it just gets blocked on the

Mongoose find() call inside for loop using a latch

梦想的初衷 提交于 2020-01-04 13:27:32
问题 I've been on this for hours and can't seem to find the answer. The problem is that I have a call to a mongoDB inside a for loop. I'm using a latch so the for waits for the call to end before advancing again. Here's my code: var latch = true; for (var i=0; i<array.length; i++) { while(latch == false){} Table1.find({}, function(err, result){ ... some code ... latch = true; }); latch = false; } The problem is that it doesn't even run the callback from Table1.find(), it just gets blocked on the

express-jwt handling specific secret passphrase by routes

こ雲淡風輕ζ 提交于 2020-01-04 12:49:18
问题 Here is my use case. In my express app using express-jwt module, I have 2 mains routes. I would like to secure my routes with 2 distincts passphrase. app.use('/api/v1/admin', jwt({secret: "blabla1"}).unless({path:['/api/v1/admin/login']})); app.use('/api/v1', jwt({secret: "blabla2"}).unless({path: ['/api/v1/login']})); In this case, it doesn't work as I was expecting to... Is there a way to achieve this in only one express app ? Thanks in advance for your helps guys! 回答1: Your syntax is a

express-jwt handling specific secret passphrase by routes

≯℡__Kan透↙ 提交于 2020-01-04 12:49:06
问题 Here is my use case. In my express app using express-jwt module, I have 2 mains routes. I would like to secure my routes with 2 distincts passphrase. app.use('/api/v1/admin', jwt({secret: "blabla1"}).unless({path:['/api/v1/admin/login']})); app.use('/api/v1', jwt({secret: "blabla2"}).unless({path: ['/api/v1/login']})); In this case, it doesn't work as I was expecting to... Is there a way to achieve this in only one express app ? Thanks in advance for your helps guys! 回答1: Your syntax is a

Detecting successful read stream open

陌路散爱 提交于 2020-01-04 12:20:13
问题 I'm implementing cache for static serving middleware for Express.js, which works as follows — when request comes, middleware first tries to serve file from filesystem, and if there is none, file is fetched from upstream and stored in file system. Problem is I don't know how to properly detect “cache hit” event. staticMiddleware = function(req, res, next) { // try to read file from fs filename = urlToFilename(req.url); stream = fs.createReadStream(filename); // cache miss - file not found