【发布时间】:2017-04-11 00:39:59
【问题描述】:
我正在尝试创建和启动服务器,但我一直在查看其他代码,但看不出为什么我的代码不起作用(只是得到这个:localhost 只是不断加载和加载,没有任何反应)。 有任何想法吗?谢谢!!!
应用程序/服务器/app.js:
'use strict'
var express= require ('express');
var path=require('path');
var bodyParser = require('body-parser');
var http = require('http');
var app= express();
module.exports = app;
app.use(express.static(path.join(__dirname, '../browser')));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var server = http.createServer();
server.listen(1337, function () {
console.log('Server is listening on port 1337!');
});
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).send(err.message);
});
应用程序/浏览器/index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>node</title>
</head>
<body>
<div>
<p>Hey whats up</p>
</div>
</body>
</html>
【问题讨论】:
标签: node.js http express server