I am using MongoDB + Node.js to create an app, but I am receiving an error for this code: company.js api.js Error friends.name: req.body.friendName, SyntaxError: Unexpected token . I also tried with friend[‘name’] but the result was the same: SyntaxError: Unexpected token [ Please tell me where is my mistake Answer Try: or: depend on what you’re after.
Tag: express
TypeError: Router.use() requires middleware function but got a Object
There have been some middleware changes on the new version of express and I have made some changes in my code around some of the other posts on this issue but I can’t get anything to stick. We had it working before hand but I can’t remember what the change was. app.js It appears the answer to this question has
Node.js, Express, EJS – Active class on current page in navigation
I’d like to render a ‘current’ class on each of my navigation links depending on which page I’m on in my layout.ejs template. Currently, my express controller index looks like this: And in my layout.ejs I have the following, which I’d like be rendered dynamically. Any ideas of how to achieve this? Answer You could include a page_name: ‘about’ in
Rest with Express.js nested router
Suppose I want to have REST endpoints which look roughly like this: CRUD on each if makes sense. For example, /user POST creates a new user, GET fetches all users. /user/user_id GET fetches just that one user. Items are user specific so I put them under user_id, which is a particular user. Now to make Express routing modular I made
Socket.io error hooking into express.js
I’m trying to hook socket.io and express.js together: At the line: var io = require(‘socket.io’).listen(app); I’m getting an error: There doesn’t seem to be anything on SO/google about this error… Answer You can do it without using http module app.listen return a server instance you can use for socket.io
Reload Express.js routes changes without manually restarting server
I tried express-livereload, but it just reloaded view files. Should I use another tool, or this one can be configured to watch for my index.js file which runs the server? I read that options are the same as node-livereload, and default for watched files include .js files. Any URL you know with a simple configuration? My main problem is how
Express Node.js doesn’t work
I installed express 4 along with node.js,npm and express-generator on my ubuntu 12.04 and created an app using the following commands: Now what I should get is “Express server running on port 3000” but instead the command simply executes and doesn’t leave any message or error. So I have no idea of which port express is running on or whether
How to generate unique ID with node.js
How to set a variable value with database query callback? How I can do it? Answer It’s been some time since I used node.js, but I think I might be able to help. Firstly, in node, you only have a single thread and are supposed to use callbacks. What will happen with your code, is that base.getID query will get
Node.js: get path from the request
I have a service called “localhost:3000/returnStat” that should take a file path as parameter. For example ‘/BackupFolder/toto/tata/titi/myfile.txt’. How can I test this service on my browser? How can I format this request using Express for instance? Answer I have not tested your code but other things works If you want to get the path info from request url 1.If you
Catch express bodyParser error
I want to catch the error from the bodyParser() middleware when I send a json object and it is invalid because I want to send a custom response instead of a generic 400 error. This is what I have and it works: But this seems to me a very ugly approach because I’m comparing the error message which could change