express

Accessing the functions in express on client side using the require — Node js

不打扰是莪最后的温柔 提交于 2020-01-07 02:47:06
问题 I have a to access the config variables defined in the file called test.js which has -- var aws = require('aws-sdk'); exports.connect = function(){ return aws; } Now I need to access it when the OnClick event occurs on the browser. I have this script but the require module does not work. clientScript.js var aws = require('../scripts/test.js').connect(); function getValue() { aws.describe({},function(){...}) } How can I access this aws variable? 回答1: You can't use require() on the client side,

Can't kill a specific worker in Node JS cluster

喜欢而已 提交于 2020-01-07 02:35:11
问题 I'm using node + express as my web server, and has a cluster of 4 workers . I tried several ways to deliberately kill a worker : process.exit() in a controller, and triggered using a browser action. Thought this is just for a single worker process, but turned out all workers were killed. Again in a controller, I let a worker send suicide announcement to the master : process.send('suicide'); and here goes my master process: if (cluster.isMaster) { console.log(`Master cluster setting up $

Sailsjs: Setting response method based on request parameter

不问归期 提交于 2020-01-07 02:25:10
问题 So I have been working on a SPA project using Sailsjs . The problem is: When the first page loads, I use res.view or res.render in my controller. But, for subsequent requests, I dont want to use res.view or res.render , rather I'd like to use res.json . Right now, I use the method: return req.param('json') ? res.json(myObj) : res.view('layout', myObj); This works, but I was looking for a more generic and abstract method in which my controller itself would know (on the basis of req.param('json

-bash express: command not found

倾然丶 夕夏残阳落幕 提交于 2020-01-06 20:25:36
问题 I am getting a very odd error trying to install the express-generator with and without sudo . I need to run: npm install express-generator -g and then express --ejs name_here but when executing the first command, I get the following error: npm ERR! Darwin 15.2.0 npm ERR! argv "node" "/usr/local/bin/npm" "install" "express-generator" "-g" npm ERR! node v0.12.7 npm ERR! npm v2.11.3 npm ERR! path /Users/[name]/.npm/lib/node_modules/express-generator/LICENSE npm ERR! code EACCES npm ERR! errno

undefined is not a valid uri or options object. in expressjs

喜夏-厌秋 提交于 2020-01-06 20:23:03
问题 I am using expressjs, after running the webapagetest i am storing the url which is in string format in a variable then i am using this variable in request node module to get the data from that url, but i am getting undefined is not a valid uri or option. here is the my javascript code var WebPageTest = require('webpagetest'); var wpt = new WebPageTest('url of private webpagetest instance server'); wpt.runTest('https://google.com', function(err, data) { console.log(err || data); console.log

receiving file in node-express uploaded with xhr

喜你入骨 提交于 2020-01-06 20:18:03
问题 I have a xmlhttprequest which uploads the file and I am trying to receive it in my node-express server. but for some reason I am not able to retrieve the file content in the server. Not sure where I am missing it. app.post('/api/uploadfiles', function(req, res) { console.log("apicalled"); console.log(req); console.log(req.body); console.log(req.files); console.log(JSON.stringify(req.files)); }); 回答1: In order for you to see the files, you will need to add another middleware that parses multi

Why won't my ExpressJS properly execute a request command?

给你一囗甜甜゛ 提交于 2020-01-06 19:33:49
问题 searchJSON = { location: 'NYC', text: text, authID: apiKey }; searchRequest = { host: siteUrl, port: 80, path: '/search', method: 'GET' }; searchResponse = makeRequest(searchRequest, searchJSON); makeRequest = function(options, data) { var req; if (typeof data !== 'string') { data = JSON.stringify(data); } req = http.get(options, function(res) { var body; body = ''; res.on('data', function(chunk) { body += chunk; }); return res.on('end', function() { console.log(body); }); }); console.log

Express Hello World — Heroku Foreman Returns Code 5, 'npm start' works just fine

不羁岁月 提交于 2020-01-06 19:25:51
问题 I'm following a tutorial in which I created a simple "Hello World" in Express. The tutorial gets everything up and running locally just fine with 'npm start'. The tutorial then moves on to prepare for uploading code to Heroku via Toolbelt. Following the directions (so far as I can tell), I execute 'foreman start'. When I hit the localhost URI, I get the basic HTML I'm expecting, but no CSS (no doubt related to the ERR_CONNECTION_REFUSED outputs I see in the console window, which is probably

no req.body sent on POST requests

青春壹個敷衍的年華 提交于 2020-01-06 18:10:58
问题 After reading many similar threads, I failed to see the reason of my problem... Im trying to learn how to create a RESTful API with node and express 4, pretty basic and simple, but when i try to save my document with a POST req, no req.body is sent on the request and i have some problems. Lets look a little piece of code: module.exports = (router, Bear) -> router.route '/bears' .get (req, res) -> Bear.find (err, bears) -> if err then err else res.json bears .post (req, res) -> newBear = _id:

Porting Express App to Meteor

旧时模样 提交于 2020-01-06 18:05:08
问题 I have been working on porting a basic Express based app to Meteor. The excellent post Is there an easy way to convert an express app to meteor? was a great start, using a waiter function to wrap iron-router routes that Meteor expects into req / res that Express likes. However, I've hit a bug that I'm stuck on. I'm not able to get Meteor to pass the res.render object over to my handlebars templating engine. For example: main.js app.get('/complex', function(req, res){ var data = { name: