How to access the GET parameters after “?” in Express?

I know how to get the params for queries like this: app.get(‘/sample/:id’, routes.sample); In this case, I can use req.params.id to get the parameter (e.g. 2 in /sample/2). However, for url like /sample/2?color=red, how can I access the variable color? I tried req.params.color but it didn’t work. 10 s 10 So, after checking out the … Read more

bodyParser is deprecated express 4

I am using express 4.0 and I’m aware that body parser has been taken out of the express core, I am using the recommended replacement, however I am getting body-parser deprecated bodyParser: use individual json/urlencoded middlewares server.js:15:12 body-parser deprecated urlencoded: explicitly specify “extended: true” for extended parsing node_modules/body-parser/index.js:74:29 Where do I find this supposed middlewares? … Read more

Error: request entity too large

I’m receiving the following error with express: Error: request entity too large at module.exports (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:16:15) at json (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/middleware/json.js:60:5) at Object.bodyParser [as handle] (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:53:5) at next (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Object.cookieParser [as handle] (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/middleware/cookieParser.js:60:5) at next (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Object.logger (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/middleware/logger.js:158:5) at next (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Object.staticMiddleware [as handle] (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/middleware/static.js:55:61) at next (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/lib/proto.js:193:15) TypeError: /Users/michaeljames/Documents/Projects/Proj/mean/app/views/includes/foot.jade:31 29| script(type=”text/javascript”, src=”https://stackoverflow.com/js/socketio/connect.js”) 30| > … Read more

Why doesn’t adding CORS headers to an OPTIONS route allow browsers to access my API?

I am trying to support CORS in my Node.js application that uses the Express.js web framework. I have read a Google group discussion about how to handle this, and read a few articles about how CORS works. First, I did this (code is written in CoffeeScript syntax): app.options “*”, (req, res) -> res.header ‘Access-Control-Allow-Origin’, ‘*’ … Read more

How to access POST form fields

Here is my simple form: <form id=”loginformA” action=”userlogin” method=”post”> <div> <label for=”email”>Email: </label> <input type=”text” id=”email” name=”email”></input> </div> <input type=”submit” value=”Submit”></input> </form> Here is my Express.js/Node.js code: app.post(‘/userlogin’, function(sReq, sRes){ var email = sReq.query.email.; } I tried sReq.query.email or sReq.query[’email’] or sReq.params[’email’], etc. None of them work. They all return undefined. When I change to … Read more

npm WARN package.json: No repository field

I installed Express.js with the following command: sudo npm install -g express I get the following warnings: npm WARN package.json [email protected] No repository field. npm WARN package.json [email protected] No repository field. npm WARN package.json [email protected] No repository field. npm WARN package.json [email protected] No readme data. npm WARN package.json [email protected] No repository field. npm WARN package.json … Read more

Error: Can’t set headers after they are sent to the client

I’m fairly new to Node.js and I am having some issues. I am using Node.js 4.10 and Express 2.4.3. When I try to access http://127.0.0.1:8888/auth/facebook, i’ll be redirected to http://127.0.0.1:8888/auth/facebook_callback. I then received the following error: Error: Can’t render headers after they are sent to the client. at ServerResponse.<anonymous> (http.js:573:11) at ServerResponse._renderHeaders (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:64:25) at ServerResponse.writeHead … Read more