Man*_*wal 15 javascript node.js
我在Centos 6服务器上安装了node,npm,我使用putty在服务器上运行命令.
节点在root上正确安装,并且在服务器的任何位置运行都很棒.
我的项目在/ 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');
Run Code Online (Sandbox Code Playgroud)
在运行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
Run Code Online (Sandbox Code Playgroud)
问题:我必须把我的节点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
Run Code Online (Sandbox Code Playgroud)
Ste*_*ght 43
这Error: listen EADDRINUSE明确表示您或守护程序正在8080上运行另一个应用程序.
但是,要检查,尝试在不同的端口上运行?
-edit-因为这得到了不少赞成,我想我会在其中添加一些额外的调试.
几乎所有node.js教程都默认使用端口8080进行运行.这是因为它类似于其他Web服务(如Apache或NGinX)使用的默认端口80.
为了确定另一个应用程序是否在同一端口上运行,您可以使用netstat -a查看所有活动连接及其端口,然后grep该列表以查找与Node.js应用程序在同一端口上连接的任何进程.
只要它是一个空闲端口,运行Node应用程序的端口并不重要.最终,当您部署到生产环境中时,您将同步所使用的任何内容服务器(Apache/NGinX)以使用相同的端口.
| 归档时间: |
|
| 查看次数: |
54922 次 |
| 最近记录: |