我已经在Centos 6服务器中安装了节点npm,并且正在使用腻子在服务器上运行命令。
Node已在根目录下正确安装,并在服务器上的任何位置运行都非常出色。
我的项目在/ home / shaadise / public_html / Ikon
我已经创建了一个hello.js文件/ home / shaadise / public_html / Ikon
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8080);
console.log('Server started');
在运行js时:
root@vps [/home/shaadise/public_html/Ikon]# node hello.js
Server started
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at Object.<anonymous> (/home/shaadise/public_html/Ikon/hello.js:6: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)
root@vps [/home/shaadise/public_html/Ikon]# throw er; // Unhandled 'error' event
-bash: throw: command not found
-bash: //: is a directory
问题:我必须将node js文件放在哪里,如何访问它?
我测试运行命令:
root@vps [/home/shaadise/public_html/Ikon]# netstat -plnt | grep ':8080'
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 27111/nginx
这Error: listen EADDRINUSE
绝对意味着您或守护程序正在8080上运行另一个应用程序。
但是,要检查是否尝试在其他端口上运行?
-edit-,因为这得到了很多支持,我想我应该在其中添加一些额外的调试功能。
几乎所有的node.js教程都默认使用端口8080进行运行。这是因为它类似于其他Web服务(例如Apache或NGinX)使用的默认端口80。
为了确定另一个应用程序是否在同一端口上运行,可以使用netstat -a
查看所有活动的连接及其端口,然后grep该列表以查找与Node.js应用程序在同一端口上连接的任何进程。
只要是免费端口,Node应用程序在哪个端口上运行都没有关系。最终,当您部署到生产环境中时,您将同步使用的任何内容服务器(Apache / NGinX)以使用同一端口。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句