node.js

Calling a middleware from within a middleware in NodeJS/ExpressJS

梦想与她 提交于 2021-02-08 11:00:58
问题 I have created some standard middleware with some logic, and depending on the logic I need to call some 3rd party middleware. Middleware is added using app.use(), which is where I add my custom middleware. Once in my middleware I no longer have access to app.use(), how do I call the middleware? Here is some code: Any ideas ? const customerData = (req, res, next) => { try { console.log('Started'); if (process.env.STORE_CUSTOMER_DATA === 'true') { // Here is some custom middleware that doesn't

Prevent all outgoing requests from NodeJS server?

爱⌒轻易说出口 提交于 2021-02-08 10:59:46
问题 Is there any existing technique or npm package that can prevent all outgoing requests from a NodeJS server, allowing only responses to incoming requests? This could prevent phone-home type attacks in deep dependencies missed in security audits. 回答1: A firewall. That's truly the only way. Remember though that there is nothing stopping some code from accepting commands from clients connecting to it. 回答2: Have a look at http://www.cyberciti.biz/tips/block-outgoing-network-access-for-a-single

Prevent all outgoing requests from NodeJS server?

纵然是瞬间 提交于 2021-02-08 10:59:36
问题 Is there any existing technique or npm package that can prevent all outgoing requests from a NodeJS server, allowing only responses to incoming requests? This could prevent phone-home type attacks in deep dependencies missed in security audits. 回答1: A firewall. That's truly the only way. Remember though that there is nothing stopping some code from accepting commands from clients connecting to it. 回答2: Have a look at http://www.cyberciti.biz/tips/block-outgoing-network-access-for-a-single

convert mongodb object to javascript object

≡放荡痞女 提交于 2021-02-08 10:54:17
问题 I pass a config file to another node.js module when starting it. The config file contain the following json: "resolution": { "activated": true, "types": [ {"of": 23} ] } When I print the received types array in the called node.js module, it looks like console.log('types array: '+ this.config.resolution.types) //output types array: [object Object] if I tried to print the text by using JSON.stringify() , I get the following result [{"of":23}] My problem start when I try to replace the types

Extract a hierarchical dataset from a flat set in Node.JS

最后都变了- 提交于 2021-02-08 10:52:14
问题 I am trying to get all the items in a flat dataset that are grouped together to form a hierarchical dataset using Javascript/Node.JS. I have a solution, but I don't think it's the most elegant and it could probably be improved. I based my solution of the answer here Find all objects with matching Ids javascript My dataset is as follows: let data = [{cid: 1, clbl: 'Rush Shipping', pid:5, plbl: 'FedEx'}, {cid: 2, clbl: 'Standard Shipping', pid:5, plbl: 'FedEx'}, {cid: 3, clbl: 'First Class',

convert mongodb object to javascript object

让人想犯罪 __ 提交于 2021-02-08 10:47:23
问题 I pass a config file to another node.js module when starting it. The config file contain the following json: "resolution": { "activated": true, "types": [ {"of": 23} ] } When I print the received types array in the called node.js module, it looks like console.log('types array: '+ this.config.resolution.types) //output types array: [object Object] if I tried to print the text by using JSON.stringify() , I get the following result [{"of":23}] My problem start when I try to replace the types

Processing a lot of requests without crashing

醉酒当歌 提交于 2021-02-08 10:47:13
问题 I am trying to send a lot of https requests and processing that causes my code to crash. I know I can increase my memory but that won't scale. Uncommenting the code below causes OOM crash at some point. The solution should probably be to flush the buffer or something, but I am learning nodejs so not sure what to do. var https = require('https'); // url anonymized for example var urlArray = ["https://example.com/blah", ....] // 5000 urls here var options = { headers: { "x-api-key": "mykey" } }

Processing a lot of requests without crashing

半腔热情 提交于 2021-02-08 10:46:31
问题 I am trying to send a lot of https requests and processing that causes my code to crash. I know I can increase my memory but that won't scale. Uncommenting the code below causes OOM crash at some point. The solution should probably be to flush the buffer or something, but I am learning nodejs so not sure what to do. var https = require('https'); // url anonymized for example var urlArray = ["https://example.com/blah", ....] // 5000 urls here var options = { headers: { "x-api-key": "mykey" } }

Extract a hierarchical dataset from a flat set in Node.JS

喜你入骨 提交于 2021-02-08 10:45:20
问题 I am trying to get all the items in a flat dataset that are grouped together to form a hierarchical dataset using Javascript/Node.JS. I have a solution, but I don't think it's the most elegant and it could probably be improved. I based my solution of the answer here Find all objects with matching Ids javascript My dataset is as follows: let data = [{cid: 1, clbl: 'Rush Shipping', pid:5, plbl: 'FedEx'}, {cid: 2, clbl: 'Standard Shipping', pid:5, plbl: 'FedEx'}, {cid: 3, clbl: 'First Class',

Firebase how to deploy cloud functions for free

这一生的挚爱 提交于 2021-02-08 10:44:22
问题 i follwed some tutorials to deploy firebase cloud functions step by step and i did not found any of this tutorial spoke about paying or something like this even the official firebase documentation but when i run firebase deploy this command i get this error firebase deploy === Deploying to 'wissal-4736a'... i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint > functions@ lint C:\Users\HP\Desktop\aaaa\functions > eslint . + functions: Finished running predeploy script.