节点.js我做错了哪一部分?服务器.js正在运行,但我看不到 HTML 页面
Node.js Which part i did wrong? server.js is running, but i cant see the html page
这是我到目前为止所拥有的,我正在腻子中运行它,
var http = require('http');
var fs = require('fs');
const POST =8080
http.createServer(function(request, response) {
var url = request.url;
switch(url) {
case '/':
console.log('1');
getStaticFileContent(response,'templates/Assignment1.html','text/html');
break;
case'/new':
console.log('2');
getStaticFileContent(response,'templates/new.html','text/html');
break;
default:
response.writeHead(404,{'Content-Type':'text/plain'});
response.end('404 - Page not Found.');
}
}).listen(POST)
console.log('Server is running');
function getStaticFileContent(response, filepath, contentType) {
fs.readFile(filepath, function(error, data) {
if (error) {
response.writeHead(500,{'Content-Type': 'text/plain'});
response.end('500 - Internal Server Error.');
}
if (data) {
response.writeHead(200,{'Content-Type': 'text/html'});
response.end(data);
}
});
}
当我在这种情况下添加这些控制台.log("1")时,会弹出这些错误。
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
at Object.<anonymous> (/net/files.cis.ksu.edu/exports/home/y/yuex/CIS526/server.js:21:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
有人可以告诉我我哪里做错了吗?
问题是服务器正在侦听同一端口,该端口已被另一个应用程序占用。释放端口,或尝试侦听另一个端口。其余代码似乎还可以。
运行此 linux 命令以检查您正在侦听的端口是否已被占用:
netstat -an | grep <port number>
或
netstat -aon | more
相关文章:
- 如何开发节点.js运行时策略
- 如何仅在通过node.js运行script.js时激发代码
- 如何从Node.js运行gullow任务-gullow.start()的任何更好的替代方案
- 使用节点 JS 运行连续后台作业
- JS运行两次不起作用
- 无法让 JS 运行
- JS - 运行带有变量名的 jQuery 函数
- 向 DOM 添加一个简单的图像标记,而不是使用 GWT 控件以获得更好的 JS 运行时性能
- 使用 express.js 和 node.js 运行我的示例应用
- 如何阻止 js 运行
- 在需要模块之前,请使用require.js运行公共代码
- 使用While True时,使用node js运行python脚本不起作用.keep-listen
- 构造Collection后,让backbone.js运行函数
- JS运行后在DOM中加载的图像
- 从node.JS运行webgl JS文件
- 只有在VS 2010中调试时才出现JS运行时错误
- 让Grunt.js运行node.js模块
- 我可以从JS运行chrome包应用程序
- 通过node.js运行带有参数的Bash脚本
- 打开和关闭Stellar.js运行时