【发布时间】:2017-12-19 10:20:18
【问题描述】:
我正在使用this tutorial 构建一个(RESTful)Node.js API。
我有一个server.js
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const app = express();
const port = 8080;
app.listen(port, () => {
console.log('We are live on ' + port);
});
我可以运行我的服务器并查看消息:
我们在 8080 上直播
我的index.js
const noteRoutes = require('./note_routes');
module.exports = function(app, db) {
noteRoutes(app, db);
// Other route groups could go here, in the future
};
还有我的node_routes.js
//create a node
module.exports = function(app, db) {
app.post('/notes', (req, res) => {
// You'll create your note here.
res.send('Hello')
});
};
index.js 和 node_routes.js 都在 app\routes\ 内部
我还下载了邮递员应用程序,以提出简单的请求
我得到了错误
无法发布 /notes
我做错了什么?? 我想不通!
【问题讨论】:
-
尝试在server.js中导入index.js
-
在 server.js 中添加这个。 require('./app/routes')(app, {});
标签: javascript node.js rest http restful-url