node.js

How to achieve DRY routers in express

邮差的信 提交于 2021-02-08 10:11:37
问题 I am building a webapp in the form of a network of sorts with basic CRUD actions. I am in the process of splitting up my router files as they are becoming rather large. I have an 'actions' route which does things such as selecting an in individual post to view, voting on a post, viewing a profile and commending a user. I cannot seem to find a way to allow me to split these 'action' routes into a seperate file and then use them as needed in the main route. //index.js file in routes folder var

How to display message using connect-flash and express-messages on .dust file on Node

你。 提交于 2021-02-08 10:09:28
问题 I'm using Nodejs and Expressjs and Kraken , I need to display message when added a product on index but I tried many time for to config but messages still not appear as I expect. Here is my config.js: var flash = require('connect-flash'); app = module.exports = express(); app.use(kraken(options)); //flash app.use(flash()); app.use(function (req, res, next) { res.locals.messages = require('express-messages')(req, res); next(); }); My controller : router.post('/somePath', function (req, res) {

Transpile a TypeScript file in memory

被刻印的时光 ゝ 提交于 2021-02-08 10:01:55
问题 I am looking for a CLI tool that can run a .ts file directly, without writing to a file. That would mean it transpiles in memory, and then somehow passes that data to the node.js executable. Does such an executable exist? 回答1: Does such an executable exist? Yes. Its called ts-node : https://github.com/TypeStrong/ts-node 来源: https://stackoverflow.com/questions/44752995/transpile-a-typescript-file-in-memory

Transpile a TypeScript file in memory

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-08 10:01:34
问题 I am looking for a CLI tool that can run a .ts file directly, without writing to a file. That would mean it transpiles in memory, and then somehow passes that data to the node.js executable. Does such an executable exist? 回答1: Does such an executable exist? Yes. Its called ts-node : https://github.com/TypeStrong/ts-node 来源: https://stackoverflow.com/questions/44752995/transpile-a-typescript-file-in-memory

Error: connect EMFILE and node-http-proxy

橙三吉。 提交于 2021-02-08 09:59:03
问题 I have a few node processes that I'm trying to reverse proxy into one localhost port. Node-http-proxy seemed like the simplest solution. I'm proxying to a couple of node.js process running express (port 3100 & 3000 in the example below), and a process running node.js with restify (2700). var http = require('http'), httpProxy = require('http-proxy'); var proxy = httpProxy.createProxyServer({}); var server = require('http').createServer(function(req, res) { if (req.url.match(/^(\/api\/search|\

Error: connect EMFILE and node-http-proxy

前提是你 提交于 2021-02-08 09:58:54
问题 I have a few node processes that I'm trying to reverse proxy into one localhost port. Node-http-proxy seemed like the simplest solution. I'm proxying to a couple of node.js process running express (port 3100 & 3000 in the example below), and a process running node.js with restify (2700). var http = require('http'), httpProxy = require('http-proxy'); var proxy = httpProxy.createProxyServer({}); var server = require('http').createServer(function(req, res) { if (req.url.match(/^(\/api\/search|\

Node : how to convert from varbinary to image of SQL Server datatype

爷,独闯天下 提交于 2021-02-08 09:58:17
问题 I'm have a SQL Server database with images of type varbinary . I need to convert the varbinary and return the image to a web page. Help would be appreciated. I found this and it was very helpful, but I need it in reverse. Node.js How to convert to image from varbinary of MS Sql server datatype Something like ... var image = new Buffer(rs.recordset[0].Image).toString('base64'); res.type('image/jpeg; charset=utf-8'); res.status(200).end(image); <ng-template ngbSlide *ngFor="let image of images"

Run function at set interval only at certain time of the day

 ̄綄美尐妖づ 提交于 2021-02-08 09:55:48
问题 I am currently running a function at regular interval round the clock. setInterval( function(){ do_this(); } , 1000*60); Unfortunately, this is not exactly what I want. I would like this function to be run at set regular interval from morning 0900hrs to 1800hrs only. The function should not run outside of these hours. How can this be done in node.js? Are there convenient modules or functions to use? 回答1: You can simply just check to see if the current time is within the desired time range or

mongoose do not return saved document in callback

徘徊边缘 提交于 2021-02-08 09:52:56
问题 I am trying to save a new record using mongoose. I am not getting the saved document in the callback. app.post("/register",(req,res) => { let userData = req.body; let user = new User(userData) user.save().then((err,doc) => { res.json({"success":true,"data":doc}); console.log(doc); }) }); I am getting doc:1. While I should get the whole document. Please help me. "dependencies": { "body-parser": "^1.18.2", "crypto-js": "^3.1.9-1", "express": "^4.15.5", "mongoose": "^4.11.13" } 回答1: You're using

how to createWriteStream() to GCS?

狂风中的少年 提交于 2021-02-08 09:51:30
问题 I'm trying to write an Express route that takes an image URI in the POST body and then saves the image into a Google Cloud Storage Bucket. I'm not able to persist this image to local disk and need to stream the buffer straight to the GCS bucket. My route creates a 4KB "stub" in the GCS bucket but there's no image payload. My nodejs then proceeds to crash... Q: What is the correct way to .pipe() the results of the https.request() to blob.createWriteStream()? Is this the right approach? I've