我正在使用this tutorial构建一个(RESTful)Node.js API。
我已经 dispatch_async(dispatch_get_main_queue(), ^{
[hud hideAnimated:YES];
});
server.js
我可以运行我的服务器并看到消息:
我们活在8080
我的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);
});
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
我还下载了post man app,发出简单的请求
我收到了错误
无法发帖/备注
我做错了什么? 我无法理解!
答案 0 :(得分:1)
server.js
您缺少require('./app/routes')(app, {});
应该是:
require('./app/routes')(app, {});
app.listen(port, () => {
console.log('We are live on ' + port);
});