express

node.js express module not loading properly

余生长醉 提交于 2020-01-02 05:22:17
问题 Geos-Mac:hone georgiana$ npm list /Users/georgiana/local/hone ├─┬ express@2.3.6 │ ├── connect@1.4.1 │ ├── mime@1.2.2 │ └── qs@0.1.0 ├── gently@0.9.0 └── mysql@0.9.1 However, a simple script that contains var express = require( 'express' ).createServer(); gives Error: Cannot find module 'express' at Function._resolveFilename (module.js:322:11) ......... when trying to use express. Please note that Geos-Mac:hone georgiana$ npm express -v 1.0.6 and Geos-Mac:hone georgiana$ node -v v0.5.0-pre Any

Regular Expression in Node.js Express Router

不想你离开。 提交于 2020-01-02 05:19:49
问题 I have tried to find a way to enter regular expression into an express routing URL and then access the variable portion of the URL through the request object. Specifically I want to route to the url "/posts/" + any number of digits. Is there a way to do this? Examples: /posts/54 /posts/2 /posts/546 回答1: This should do it: app.get('/posts/:id(\\d+)', function(req, res) { // id portion of the request is available as req.params.id }); EDIT : added regex to path to limit it to digits 回答2: I agree

How to add --harmony node flag to grunt-express

我的梦境 提交于 2020-01-02 04:50:34
问题 I'm using grunt-express to do local development. here is my GruntFile.js var path = require('path'); module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify:{ options:{ banner:'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' } }, express:{ server:{ options:{ debug:true, server: path.resolve('app.js') } } }, env : { options:{ }, dev : { NODE_ENV : 'development' }, prod : { NODE_ENV : 'production' } }, mochaTest:{ test:{ options:

Remove csrf protecteion on API post calls

拈花ヽ惹草 提交于 2020-01-02 04:44:07
问题 I would like to remove csrf from my Express 3.0 application as i don't need it there. I use oauth to validate clients. Is the a middleware to whitelist API urls when using express.csrf()? 回答1: You can do that in two ways. 1.) Create a small middleware of your own to allow white list url patterns not to be blocked by csrf like; var express = require("express"); var expressCsrf = express.csrf(); var app = express.createServer(); var customCsrf = function (req, res, next) { // I assume exact

NodeJS Post request using a Button

◇◆丶佛笑我妖孽 提交于 2020-01-02 04:30:09
问题 I don't know if this is possible or not. All the research I've done has shown that it is possible with a form and text input. But anyways, Using NodeJs & Express I want to be able to click a button on my webpage, and once it's clicked, it sends a post request to my Node.JS server. Simpler way of saying it: When button is clicked, send info to the server. Goal I'm trying to achieve: When button is clicked, it sends some sort of ID/code/anything to turn on a service from my database. (I have

Unable to access req.user with Passport.js and Express 4

南楼画角 提交于 2020-01-02 03:12:06
问题 I've been creating an app with Passport, Express 4 and Jade. I would like to show the user a navbar that changes when they log in. However, I cannot access req.user for any other page than the profile page, which calls isLoggedIn: function isLoggedIn(req, res, next) { // if user is authenticated in the session, carry on if (req.isAuthenticated()) return next() // if they aren't redirect them to the home page res.redirect("/login") } Using any other function to not redirect the user when not

Lodash merge with mongoose

不想你离开。 提交于 2020-01-02 03:06:16
问题 Here is a code snippet of an update method using express.js and mongoose. I'm trying to merge the existing mongo entity with the json object from the request payload body. exports.update = function(req, res) { if(req.body._id) { delete req.body._id; } Entity.findById(req.params.id, function (err, entity) { if (err) { return handleError(res, err); } if(!entity) { return res.send(404); } var updated = _.merge(entity, req.body); updated.save(function (err) { if (err) { return handleError(res,

Error: listen EACCES on Openshift app

主宰稳场 提交于 2020-01-02 02:12:24
问题 I have the following code var express = require('express') , app = express() , server = require('http').createServer(app) , io = require('socket.io').listen(server) , connect = require('connect') , pg = require('pg') , Client = pg.Client; // Setup express middleware app.use(express.static('public')); app.use(connect.logger()); // Start the server var port = process.env.OPENSHIFT_INTERNAL_PORT || 8080 , ip = process.env.OPENSHIFT_INTERNAL_IP || "127.0.0.1"; server.listen(port, ip); But when

Routes folder in Express

狂风中的少年 提交于 2020-01-02 00:52:16
问题 When you create an Express application you get a routes folder. All routes are registered in the app.js file. However the logic on what happens is located in the files of the routes folder. Is this a synonym for controller folders in other frameworks? Is this the location of where you should add the request/response logic? 回答1: Yes, is kind of the same thing as a controller folder. IMO, you better use different files as you would with controllers in another language because when the

XmlHttpRequest getAllResponseHeaders() not returning all the headers

不问归期 提交于 2020-01-02 00:42:25
问题 I'm trying to get the response headers from an ajax request but jQuery's getAllResponseHeaders xhr method only displays the "Content-Type" header. Anyone know why? This is the response header Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:If-Modified-Since, Cache-Control, Content-Type, Keep-Alive, X-Requested-With, Authorization Access-Control-Allow-Methods:GET, PUT, POST, DELETE, OPTIONS Access-Control-Allow-Origin:* Access-Control-Max-Age:1728000 Authorization:apikey=