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 trialSteve Anderson
4,850 PointsERR_INCOMPLETE_CHUNK is an error I keep getting from treehouse.
This page isnβt working
port-3000-6cyk143ym6.treehouse-app.com unexpectedly closed the connection. ERR_INCOMPLETE_CHUNKED_ENCODING
This is before I finished the error handling function. This message appears when I try to load the user data. Is this a treehouse issue or on my side?
app.js:
var router = require('./router.js');
//Use node to perform profile look ups and server our template via HTTP. Look at user's bade count and JavaScript points from a web browser.
//Create a seb server
const http = require('http');
const hostname = '';
const port = 3000;
const server = http.createServer((request, response) => {
router.home(request, response);
router.user(request, response);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
//Function that handles the reading of files and merge in values.
//read from file and get a string
//merge values into String
router.js:
var Profile = require("./profile.js");
//Handle HTTP route Get/ and Post / i.e. Home
function home(request, response){
// if url == "/" && GET
if(request.url === '/') {
//show search
response.writeHead(200, {'Content-Type':'text/plain'});
response.write('Header\n');
response.write('Search\n');
response.end('Footer\n');
}
//if url == "/" && POST
//redirect to /:username
}
//Handle HTTP route GET /:username i.e./chalkers
function user(request, response){
// if url === "/..."
//user is /username, remove first slash to get username
var username = request.url.replace("/", "");
if (username.length > 0) {
response.writeHead(200, {'Content-Type':'text/plain'});
response.write('Header\n');
//get JSON from Treehouse
var studentProfile = new Profile(username);
//on "end"
studentProfile.on("end", function(profileJSON){
// show profile
//store values we need
var values = {
avatarUrl: profileJSON.gravatar_url, //root of JSON object
username: profileJSON.profile_name,
badges: profileJSON.badges.length,
javascriptPoints: profileJSON.points.JavaScript
}
//simple response
response.write(values.username + ' has ' + values.badges + ' badges\n');
response.end('Footer\n');
});
// on "error"
studentProfile.on("error", function(error){
//show error
//response.write(error.message + '\n');
//response.end('Footer\n');
});
}
}
module.exports.home = home;
module.exports.user = user;