How to set up Apache ProxyPass to preserve Express routes

In my Apache config im forwarding all traffic on /node to port 3000, where the Express server is listening. <IfModule mod_proxy.c> ProxyRequests Off ProxyPass /node http://localhost:3000/ </IfModule> The Express app looks like this: var express = require(‘express’); var app = express(); var router = express.Router(); router.route(‘/route/:id’).get(function (req, res) { res.json({ description: ‘Welcome to a route […]

How to setup node-schedule for every day at 12am

I am using node-schedule to schedule my tasks. Now I need to schedule a job everyday at 12am. Below given is the code I am using, var rule3 = schedule.scheduleJob(’00 00 00 * * *’, function(){ console.log(‘my test job!’); }); This is not working for me. Any help appreciated. Thanks in advance.

nodejs applicaiton giving error “%1 is not a valid Win32 application” in windows machine

My Nodejs application works fine in ubuntu. When i tried to deploy the same in Windows machine it showed below error. =>node server.js D:\home\site\wwwroot D:\home\site\wwwroot\node_modules\ffi\node_modules\bindings\bindings.js:83 throw e ^ Error: %1 is not a valid Win32 application. D:\home\site\wwwroot\node_modules\ffi\node_modules\ref\build\Release\binding.node at Error (native) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at bindings I […]

Failed to lookup view, correct filename and location

I was following instructions from here:, when i got this error when trying to run my code, Error: Failed to lookup view “index.ejs” in views directory “Directory/views” at EventEmitter.render (Directory/node_modules/express/lib/application.js:579:17) at ServerResponse.render (Directory/node_modules/express/lib/response.js:961:7) at Directory/ourMeanJS/config/routes.js:10:13 at Layer.handle [as handle_request] (Directory/node_modules/express/lib/router/layer.js:95:5) at next (Directory/node_modules/express/lib/router/route.js:131:13) at Route.dispatch (Directory/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (Directory/node_modules/express/lib/router/layer.js:95:5) at Directory/node_modules/express/lib/router/index.js:277:22 at […]

Express default route parameter

I am surprised I can’t find this so it has probably been answered before (and I’m searching for the wrong thing). Basically, is it possible and how do I set a default value on a nodejs express route? // Test route router.route(‘/tests/:id’) .get(testsController.tests.get); Where if :id is not set, it will automatically set to an […]

Mongodb multi document insert ignore custom duplicate field error

I have to insert 3 recordset from array 1 already exists and 2 are new e.g: db.products.insert( [ { imagename: “pen1”, qty: 21 }, { imagename: “pen”, qty: 20 }, { imagename: “eraser”, qty: 25 } ] ) Wherein “{ imagename: “pen”, qty: 20 }”` already exists and has unique key on field “imagename” in […]

Correct way to translate ES6 “import” to nodejs “require”

I’m tryng to reproduce the example reported here inside my project. The problem is that I’m using Browseryfy that seems to not support ES6 imports. So I thought of translate the third import of the example from: import {Treebeard} from ‘react-treebeard’; to var Treebeard = require(‘react-treebeard’).default; But it still not works, and I get the […]

What encodings does Buffer.toString() support?

I’m writing an app in node.js, and see that I can do things like this: var buf = new Buffer(“Hello World!”) console.log(buf.toString(“hex”)) console.log(buf.toString(“utf8”)) And I know of ‘ascii’ as an encoding type (it’ll take an ASCII code, such as 112 and turn it into a p), but what other types of encoding can I do?

How to replace Promise.defer with new Promise()

So I see that Promise.defer is now deprecated and we are now supposed to use new Promise instead. I don’t see how to do this however for this example? var Promise = require(‘bluebird’); var interval; var rollDice = function (resolver) { console.log(“rolling”); if (Math.floor(Math.random() * 10) == 7) { clearInterval(interval); resolver.resolve(); } } var rollTill7 […]

nodejs auto refresh view after database updates

I would like use nodeJS to refresh my view, every time a function has made changes to the database. If we take MEAN-stack as an example, I don’t want to send an $http-request every x seconds to check if changes have been made to the database. I would like the front end to get notified […]

Node.js is the Best Javascript runtime in the world.