Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 634 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
node.js Error: connect ECONNREFUSED; response from server

#1
I have a problem with this little program:

<!-- begin snippet: node hide: false -->

<!-- language: lang-node -->

var http = require("http");
var request = http.request({
hostname: "localhost",
port: 8000,
path: "/",
method: "GET"
}, function(response) {
var statusCode = response.statusCode;
var headers = response.headers;
var statusLine = "HTTP/" + response.httpVersion + " " +statusCode + " " + http.STATUS_CODES[statusCode];
console.log(statusLine);
for (header in headers) {
console.log(header + ": " + headers[header]);
}
console.log();
response.setEncoding("utf8");
response.on("data", function(data) {
process.stdout.write(data);
});
response.on("end", function() {
console.log();
});
});

<!-- end snippet -->

The result in console is this:

<pre>
events.js:141
throw er; // Unhandled 'error' event
^

Error: connect ECONNREFUSED 127.0.0.1:8000
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)</pre>

I do not understand why this happens.
Reply

#2
use a proxy property in your code it should work just fine

const https = require('https');
const request = require('request');

request({
'url':'https://teamtreehouse.com/chalkers.json',
'proxy':'http://xx.xxx.xxx.xx'
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = body;
console.log(data);
}
}
);
Reply

#3
From your code, It looks like your file contains code that makes get request to localhost (127.0.0.1:8000).

The problem might be you have not created server on your local machine which listens to port 8000.

For that you have to set up server on localhost which can serve your request.

1. Create server.js


var express = require('express');
var app = express();

app.get('/', function (req, res) {
res.send('Hello World!'); // This will serve your request to '/'.
});

app.listen(8000, function () {
console.log('Example app listening on port 8000!');
});

2. Run server.js : node server.js

3. Run file that contains code to make request.
Reply

#4
I had the same problem on my mac, but in my case, the problem was that I did not run the database (sudo mongod) before; the problem was solved when I first ran the mondo sudod on the console and, once it was done, on another console, the connection to the server ...
Reply

#5
Please use [::1] instead of localhost, and make sure that the port is correct, and put the port inside the link.

const request = require('request');

let json = {
"id": id,
"filename": filename
};
let options = {
uri: "http://[::1]:8000" + constants.PATH_TO_API,
// port:443,
method: 'POST',
json: json
};
request(options, function (error, response, body) {
if (error) {
console.error("httpRequests : error " + error);
}
if (response) {
let statusCode = response.status_code;
if (callback) {
callback(body);
}
}
});
Reply

#6
i ran the local mysql database, but not in administrator mode, which threw this error
Reply

#7
If you have stopped the mongod.exe service from the task manager, you need to restart the service. In my case I stopped the service from task manager and on restart it doesn't automatically started.
Reply

#8
I got this error because my AdonisJS server was not running before I ran the test. Running the server first fixed it.
Reply

#9
Just run the following command in the node project:

npm install

Its worked for me.
Reply

#10
I solved this problem with `redis-server`, you can install that like this!

> `sudo apt-get install redis-server`

after that see the port and change it!
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through