我刚启动nodejs,并按照步骤在loalhost:3000上显示文本,但是当我在命令行上继续使用nodemon server.js时,它没有显示任何响应。
此页面无效 本地主机未发送任何数据。
ERR_EMPTY_RESPONSE
server.js
const express = require('express');
const bodyParser = require('body-parser');
const ejs = require('ejs');
const http = require('http');
const container = require('./container');
container.resolve(function (users) {
const app = SetupExpress();
function SetupExpress() {
const app = express();
const server = http.createServer(app);
server.listen(3000, function () {
console.log('Listening to port 3000');
});
ConfigureExpress(app);
//setup router
const router = require('express-promise-router')();
users.SetRouting(router);
app.use(router);
}
function ConfigureExpress(app) {
app.use(express.static('public'));
app.set('view engine', 'ejs');
app.use(bodyParser.json);
app.use(bodyParser.urlencoded({extended: true }));
}
});
users.js
'use strict';
module.exports = function (_) {
return {
SetRouting: function (router) {
router.get('/', this.indexPage);
},
indexPage: function (req, res) {
return res.render('index', {test: 'This is a test!'});
}
}
}
container.js
'use strict';
module.exports = function (_) {
return {
SetRouting: function (router) {
router.get('/', this.indexPage);
},
indexPage: function (req, res) {
return res.render('index', {test: 'This is a test!'});
}
}
}
index.ejs
<%=test%>