以下代碼是我的第一個Express
restfull應用程序。運行server.js
後,我在FireFox中進入http://localhost:3020/helloworld
網址後,預計我得到Hello, World!
消息,但我得到這個消息:Nodejs無法在簡單應用程序中獲取/ helloworld
Cannot GET /helloworld
代碼:
var express = require('express');
var router = express.Router();
var app = express();
var server = require('http').createServer(app);
var port = process.env.PORT || 3020;
/* GET home page. */
router.get('/helloworld', function(req, res) {
res.render('helloworld', { title: 'Hello, World!' });
});
server.listen(port, function() {
console.log('Server listening at port %d', port);
});
快速路由器的文檔 - http://expressjs.com/en/guide/routing .html#express-router –