ana*_*ana 30 javascript port http node.js express
我编写了一个简单的代码并将其保存在try.js文件中.
var http = require('http');
var makeRequest = function(message) {
var options = {
host: 'localhost', port: 8080, path: '/', method: 'POST'
}
var request = http.request(options, function(response){
response.on('data', function(data){
console.log(data);
});
});
request.write(message);
request.end();
}
makeRequest("Here's looking at you, kid.");
Run Code Online (Sandbox Code Playgroud)
当我通过终端运行它时会出错
throw er; // Unhandled 'error' event,
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
at Object.afterConnect [as oncomplete] (net.js:875:19)error' event
Run Code Online (Sandbox Code Playgroud)
另一台服务器在同一端口8080上运行,因此您需要终止并启动您的实例.
找到运行实例
$ netstat -nlp | grep 8080
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::8881 :::* LISTEN 28207/node
Run Code Online (Sandbox Code Playgroud)
使用pid杀死现有服务器实例
$ kill -9 28207
Run Code Online (Sandbox Code Playgroud)
开始实例
$ node server.js
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
59640 次 |
最近记录: |