express

Node.js Rest call to a server that requires a certificate

懵懂的女人 提交于 2020-01-15 06:05:41
问题 How do a make a rest call from Node.js to a server that requires a certificate for authentication? 回答1: The solution is to use a custom connection pool, for which you'll need to use a custom Agent. Here's an example using the standard https module, straight from the documentation: var options = { hostname: 'encrypted.google.com', port: 443, path: '/', method: 'GET', key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem') };

Saving multiple files using Promise

↘锁芯ラ 提交于 2020-01-15 05:55:27
问题 I have a Node URL (created using Express) that can be used to download a static image of an address. So, the calling app calls the /download url and passes multiple addresses using json, then the download service would call Google Maps and save the static image of each of these addreses on the node server (it would then send it back to the calling application, but for the purpose of this question I am only interested in saving the images in the node server). Initially, we were only interested

Express node.js controller not waiting for data manipulation and returning old data

末鹿安然 提交于 2020-01-15 05:13:08
问题 I am using express.js , node.js to connect mongoDB. My aim I have a quiz-collection . I have an **answers-collection****. When I am showing the user the quiz list, I want to show the user if he/she has already participated in any of the quizzes. My way I added a Boolean field to each document in quiz collection as "user_participated" : false . When my route calls "/all-quizzes", it calls a function from controller, which first sets all the document "user_participated" false in side a forEach,

express3-handlebars and 18next-node - internationalisation based on page?

送分小仙女□ 提交于 2020-01-15 05:00:12
问题 my first question here - please go easy. I'm using express, express3-handlebars and i18next-node with node.js The plan is to work with a different translation namespace depending on which view (i.e. which handlebars file) is currently being served. So if we're looking at the page called ie(.hbs), i18next will look in the namespace called ie(.json) for the relevant language. This makes organisation and coordination of translations easier. This is how I'm currently doing it: first I send the

How to solve CORS request did not succeed in express.js when react client try fetch data?

百般思念 提交于 2020-01-15 03:29:06
问题 I done so many changes in app.js file to solve this issue CORS request did not succeed but i always facing the same issue.How to solve this issue. I added my app.js code please check anyone. thanks app.js Code var express = require('express'); var bodyParser = require("body-parser"); var app = express(); var cors = require('cors'); const userlogin = require('./routes/User_route'); const deviceRoutes = require("./routes/Device_route"); app.use('*', cors()); app.use(bodyParser.json()); app.use

Nodejs MaxListenersExceededWarning

为君一笑 提交于 2020-01-15 03:21:53
问题 I have an error and I don't know how to solve it. It happens only some times. Error message: (node:9140) MaxListenersExceededWarning: Possible EventEmitter memory leak detec ted. 11 error listeners added. Use emitter.setMaxListeners() to increase limit 回答1: This error often occurs when you are using EventEmitters directly or indirectly in your code and you are creating too many in too short a period for them to be resolved -- Node detects this as a memory leak and throws an error once the Max

NodeJS Router payload too large

喜夏-厌秋 提交于 2020-01-14 22:44:07
问题 I'm creating rest endpoints in my nodejs application as follows: In my server.js I have the following code: var express = require('express'); var app = express(); app.use(express.json({ limit: '50mb' })); app.use(express.urlencoded({ limit: '50mb', extended: true })); app.use(require('./routes/APIRoutes')); I also tried the code below instead of using the express.json and expres.urlencoded as suggested on the potential duplicate question. var app = express(); var bodyParser = require('body

Express sendfile and redirect url

旧城冷巷雨未停 提交于 2020-01-14 14:49:29
问题 I have a bunch of middleware. At the first app.use I test if the process is under duress, and if so I want it to just send the static /index.html file and redirect the user's browser to "/#" + req.url . for example: app.set("port", PORT) //etc app.use(function(req, res, next) { if (something) res.sendfile('/public/index.html', { root: __dirname + '/..' }) // also, redirect the user to '/#' + req.url else next() }); // a ton more middleware that deals with the main site app.use(express.static(

Node Express Jade - Checkbox boolean value

时间秒杀一切 提交于 2020-01-14 14:33:31
问题 I'm using Node+Express+Jade to render some webpages. On a form there are 2 checkboxes. When the form is submitted through POST, if the checkbox is checked, I get req.body.checkbox1 -> 'on' , if isn't checked, I get req.body.checkbox1 -> undefined Is possible to get checkbox value as true or false ? Here's my server side test code var bodyParser = require('body-parser'); var express = require('express'); var app = express(); app.use(bodyParser.urlencoded({extended: true})); app.use(express

find matched item from document based on regex value in mongidb

痴心易碎 提交于 2020-01-14 13:57:08
问题 I have to select matched casts item [ m_credits_cast ] from the Movie collection by using Regex value. Movie Modal var mongoose = require('mongoose'); var movieSchema = new mongoose.Schema({ m_tmdb_id: { type: Number, unique: true, index: true }, m_original_title: { type: String }, m_poster_path: { type: String }, m_credits_cast: { type: Array }, m_release_date: { type: Date }, m_title: { type: String }, created_at: { type: Date }, updated_at: { type: Date, default: Date.now } }); var