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 trialAshish Mehra
523 PointsUnable to get errors on my page (Reading from files - Node)
var Profile = require("./profile.js");
var render = require("./rendering.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'});
render.construct("header",{},response);
render.construct("search",{},response);
render.construct("footer",{},response);
response.end();
}
//if url == "/" && POST
//redirect to /:username
}
//Handle HTTP route GET /:username i.e. /chalkers
function user(request, response) {
//if url == "/...."
var username = request.url.replace("/", "");
if(username.length > 0) {
response.writeHead(200, {'Content-Type': 'text/plain'});
render.construct("header",{},response);
//get json from Treehouse
var studentProfile = new Profile(username);
//on "end"
studentProfile.on("end", function(profileJSON){
//show profile
//Store the values which we need
var values = {
avatarUrl: profileJSON.gravatar_url,
username: profileJSON.profile_name,
badges: profileJSON.badges.length,
javascriptPoints: profileJSON.points.JavaScript
}
//Simple response
render.construct("profile",values,response);
render.construct("footer",{},response);
response.end();
});
//on "error"
studentProfile.on("error", function(error){
//show error
render.construct("header",{},response);
render.construct("error",{errorMessage : "There is an error in getting profile (Not found)"+error.message})
render.construct("footer",{},response);
response.end();
});
}
}
module.exports.home = home;
module.exports.user = user;
<!-- Response I am getting -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Treehouse Profile</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css" media="screen">
@import url(http://fonts.googleapis.com/css?family=Varela+Round);
@import url(http://necolas.github.io/normalize.css/3.0.2/normalize.css);
body {
background: #ECEEEF;
text-align: center;
margin: 100px auto;
max-width: 462px;
padding: 0 40px;
font: 18px normal 'Varela Round', Helvetica, serif;
color: #777B7E;
}
img {
width: 100%;
}
#searchIcon, #avatar {
width: 50%;
border-radius: 50%;
margin: 0 25% 0 25%;
}
input {
font-family: 'Varela Round', Helvetica, serif;
font-size: 18px;
padding: 31px 0;
margin: 10px 0;
text-align: center;
width: 360px;
border-radius: 4px;
border: 1px solid #D5DDE4;
color: #2C3238;
}
#username {
margin: 20px 0 0;
}
.button {
border-color: #5FB6E1;
background: #5FB6E1;
color: #fff;
}
#error {
width: 100%;
padding: 22px 0;
background: #FFE6B2;
color: #C5A14E;
position: absolute;
left: 0;
top: 0;
}
#profile {
background: #fff;
border-radius: 4px;
border: 1px solid #D5DDE4;
padding: 40px 0 0;
margin: -40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
margin: 40px 0 0;
}
li {
display: inline-block;
width: 100%;
padding: 22px 0;
margin: 0;
border-top: 1px solid #D5DDE4;
}
a, a:visited {
color: #5FB6E1;
text-decoration: none;
}
span {
color: #2C3238;
}
</style>
</head>
<body>
//no error
//no footer
1 Answer
Seth Kroger
56,413 PointsI notice that every other time you call render.construct() you use three arguments, with the third being response. When you call it for the error template, it only has two.