Skip to content
Advertisement

Tag: express

SyntaxError: Unexpected token

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.

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

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

Advertisement