I'm trying to set up a rest API that runs on my node.js HTTP server. For regular calls, I want the path to be /...
, for API calls, I want to use /API/...
.
From what I can gather from various webpages, including http://expressjs.com/guide/routing.html, what I need is something like this:
var express = require('express');
var app = express();
var router = express.Router();
/* set up app ... */
router.route('/some/url').get(...).put(...);
app.use('/API', router);
For some reason, however, the third line (var router = ...
) always returns undefined
. When I debug, I can plainly see that express.Router()
is a function with no return statement, but does include a bunch of this.foo
setters. This makes me think that I should be calling var router = new express.Router()
, but I can't find any documentation to support that claim.
Ideas on what's going wrong?
My project dependencies in my packages.json
files are:
"dependencies": {
"body-parser": "^1.12.2",
"express": "^3.4.4",
"express-react-views": "^0.7.1",
"fluxxor": "^1.5.2",
"mongoose": "^4.0.1",
"react": "^0.12.2"
}