Tag: express

Is it possible to have redirection follow a rendering in express + node js?

I have use case where there needs to be rendering followed by redirection. Rendering is supposed to inform user about successful transaction using inherit view model followed by redirection to home page. Following is desired code: router.post(‘/posturi’, function(req, res, next) { //Call few services if(err){ return res.render(‘/errorpage’) } res.render(‘/transaction page’); //TimeOut function goes here res.redirect(‘/home’); […]

Loopback-component-storage: How to convert image to thumbnail before uploading to Amazon S3

I am using loopback component storage for uploading image to server. I want to convert each image that been uploaded through server to a thumbnail view and save it to the container. Initially I was using local file storage to store file and everything was working fine. In file storage I was using “quickthumb” for […]

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 […]

Failed to lookup view, correct filename and location

I was following instructions from here: https://scotch.io/tutorials/easy-node-authentication-setup-and-local, 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 […]

Can I pass variable to required file?

In express, I’m trying to move my minification to a requierd file: app.js: var app = express(); var minify = require(“./minify.js”); In that file I try to set my template engine. minify.js: var app = express(); app.engine(‘html’, mustacheExpress()); Later when I try to use to use the rendering engine in app.js, I get the error […]

Argument error, options.body in node.js?

what is the problem i don’t know please help to solve this. when i post data then below error shows on terminal. Attach is the code also. Error: Argument error, options.body. at Request.init (/usr/lib/nodejs/request/index.js:351:13) at new Request (/usr/lib/nodejs/request/index.js:124:8) at Object.request (/usr/lib/nodejs/request/index.js:1279:11) at Request._callback (/var/www/html/nodeproject/helloworld/controllers/login.js:68:11) at Request.self.callback (/usr/lib/nodejs/request/index.js:148:22) at Request.EventEmitter.emit (events.js:98:17) at Request.<anonymous> (/usr/lib/nodejs/request/index.js:896:14) at Request.EventEmitter.emit […]

Set cache header in hapi

How can I set the cache-control header in hapi to ‘no-cache’, ‘no-store’, ‘must-revalidate’? In express I am able to do the following: res.header(‘Cache-Control’, ‘no-cache, no-store, must-revalidate’); I currently have the following in hapi but I think it may be incorrect: function(request, reply){ var response = reply(); response.header(‘Cache-Control’, ‘no-cache’); response.header(‘Cache-Control’, ‘no-store’); response.header(‘Cache-Control’, ‘must-revalidate’ } Is it […]

Express handling URIError: Failed to decode param

var express = require(‘express’); var app = express(); app.get(‘*’, function (req, res) { var host = req.get(‘Host’); return res.redirect([‘https://’, host, req.url].join(”)); }); var server = app.listen(8080, function () { console.log(‘starting’); }); I have a simple script that redirects http to https. This is working fine except when there is a malformed url for example: website.com/%c0%ae%c0%ae. […]

Socket hang-up using neo4j JS driver

all. I’m new to neo4j and trying to use the official JS driver from node / express to hit a remote (e.g. non-local) server, but keep getting [Error: socket hang up] code: ‘ECONNRESET’ errors. Code looks like this: router.get(‘/’, function(req, res, next) { var driver = neo4j.driver(“bolt://ip.address”, neo4j.auth.basic(“neo4j”, “neo4j”)); var session = driver.session(); var query […]

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