Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Peter Mingione
11,874 Pointstest ... node example_profile.js ... is not working
The test ... node example_profile.js ... is not working. I get this error ...
AggregateError [EBADF]:
at internalConnectMultiple (node:net:1117:18)
at afterConnectMultiple (node:net:1684:7)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:500:9)
at TLSSocket.emit (node:events:520:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'EBADF',
[errors]: [
Error: connect EBADF 52.54.79.234:443
at createConnectionError (node:net:1647:14)
at afterConnectMultiple (node:net:1677:16) {
errno: -9,
code: 'EBADF',
syscall: 'connect',
address: '52.54.79.234',
port: 443
},
Error: connect EBADF 34.198.233.37:443
at createConnectionError (node:net:1647:14)
at afterConnectMultiple (node:net:1677:16) {
errno: -9,
code: 'EBADF',
syscall: 'connect',
address: '34.198.233.37',
port: 443
}
]
}
Peter Mingione
11,874 PointsHi Steven, Thanks for answering. The code is in the lesson (https://teamtreehouse.com/library/build-a-simple-dynamic-site-with-nodejs/preparing-planning). And also here it is:
Profile.js ...
var EventEmitter = require("events").EventEmitter;
var https = require("https");
var http = require("http");
var util = require("util");
function Profile(username) {
EventEmitter.call(this);
var profileEmitter = this;
//Connect to the API URL (https://teamtreehouse.com/username.json)
var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response) {
var body = "";
if (response.statusCode !== 200) {
request.abort();
//Status Code Error
profileEmitter.emit("error", new Error("There was an error getting the profile for " + username + ". (" + http.STATUS_CODES[response.statusCode] + ")"));
}
//Read the data
response.on('data', function (chunk) {
body += chunk;
profileEmitter.emit("data", chunk);
});
response.on('end', function () {
if(response.statusCode === 200) {
try {
//Parse the data
var profile = JSON.parse(body);
profileEmitter.emit("end", profile);
} catch (error) {
profileEmitter.emit("error", error);
}
}
}).on("error", function(error){
profileEmitter.emit("error", error);
});
});
}
util.inherits( Profile, EventEmitter );
module.exports = Profile;
And this is the file that is run (example_profile.js)
var Profile = require("./profile.js");
var studentProfile = new Profile("profiles/petermingione");
studentProfile.on("end", console.dir);
studentProfile.on("error", console.error);
It is run in the console ...
node example_profile.js
When I run it in work spaces it works fine. When I run it on my local machine it get the error that I previously described. Thanks for the help
Peter Mingione
11,874 PointsGemini says:
Connection Attempt Failure: The [errors] array shows that the process failed to connect to two specific IP addresses on port 443 (standard HTTPS port).
Steven Parker
243,253 PointsWhen I run this code in a workspace made from the course, I don't get any error. I see your profile data as a JSON string.
2 Answers
Steven Parker
243,253 PointsThat Gemini result might be telling us that the problem is caused by your local environment not having a working internet connection.
Steven Parker
243,253 PointsPeter Mingione — I guess we could call an over-eager firewall a "not working internet connection".
Hope I helped. You can mark a question solved by choosing a "best answer".
And happy coding!
Peter Mingione
11,874 PointsHi Steven, Thanks for the reply. I have discovered the problem. It was my firewall. Now that I have turned it off the app works. Thanks again.
Steven Parker
243,253 PointsSteven Parker
243,253 PointsSharing your code is more important that showing the errors. We can recreate the errors using it, but also find the cause of the issue.
Here's a video about how to make a snapshot of your workspace and you can then post the link to it here.