【发布时间】:2014-12-19 07:08:05
【问题描述】:
我对 Node Js 和 Express Js 真的很陌生,我正在关注(书)[http://www.sitepoint.com/store/jump-start-node-js/] 来学习 Node Js。
在书中作者为简单的登录表单创建了一个简单的页面。我正在关注它,但得到 404 Not found。
Not Found
404
Error: Not Found
at Layer.app.use.res.render.message [as handle] (/Applications/MAMP/htdocs/resto/app.js:29:15)
at trim_prefix (/Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:240:15)
at /Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:208:9
at Function.proto.process_params (/Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:269:12)
at next (/Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:199:19)
at next (/Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:176:38)
at /Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:137:5
at /Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:250:10
at next (/Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:160:14)
at next (/Applications/MAMP/htdocs/resto/node_modules/express/lib/router/index.js:176:38)
我在 App.js
中添加了以下代码var fs = require('fs');
app.get('/form', function(req, res){
fs.readFile('.views/form.html', function(error, content){
if(error){
res.writeHead(500);
res.end();
}
else{
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(content, 'utf-8');
}
});
});
然后在 Views 文件夹中创建了一个文件 form.html,我在其中创建了一个简单的 html 表单。
这对我不起作用,所以按照默认 index.jade 的流程,我创建了一个文件 form.js 并在其中添加了以下代码
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/form', function(req, res) {
res.render('form');
});
module.exports = router;
这也不起作用。我确定我做错了什么,但我不知道在哪里。
请帮忙,谢谢
【问题讨论】:
标签: javascript node.js express