Node.js: GET Request returns 404 Not Found
I just ran your code but with replacing xxxx with a port number. It worked fine for me.
var express = require('express');var app = express();app.get('/bits', function(req, res) { res.send([{name:'bit1'}, {name:'bit2'}]);});app.get('/bits/:id', function(req, res) { res.send({id:req.params.id, name: "The Name", description: "description"});});app.listen(8080);console.log('Listening on port 8080.');
I ran the some curl commands as well to show it working.
[09:24 AM] jsloyer@Jeffs-MacBook-Pro [Downloads]>curl http://127.0.0.1:8080/bits[{"name":"bit1"},{"name":"bit2"}][09:25 AM] jsloyer@Jeffs-MacBook-Pro [Downloads]>curl http://127.0.0.1:8080/bits/1{"id":"1","name":"The Name","description":"description"}[09:25 AM] jsloyer@Jeffs-MacBook-Pro [Downloads]>
Additionally here is a whole Node.js git project including the source for it.
You can click the button below to deploy it as well to see it in action.