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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Sandro Das Neves](https://secure.gravatar.com/avatar/c7ce6c07c247e4c358fbacc6c8877622?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sandro Das Neves
Front End Web Development Techdegree Graduate 23,426 Pointshow to type the good url ?
I've the exact same code but in my local machine when I add /username at the end of the url it doesn't do anything. can someone help me please ?
![Sandro Das Neves](https://secure.gravatar.com/avatar/c7ce6c07c247e4c358fbacc6c8877622?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sandro Das Neves
Front End Web Development Techdegree Graduate 23,426 Pointsyeah how can I post my code here ? maybe a link to a repo on git hub ?
![Sandro Das Neves](https://secure.gravatar.com/avatar/c7ce6c07c247e4c358fbacc6c8877622?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sandro Das Neves
Front End Web Development Techdegree Graduate 23,426 Pointsconst router = require('./router.js');
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
router.home(req,res);
router.user(req,res);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
function home(req,res) {
if (req.url === "/") {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.write('Header\n');
res.write('Search\n');
res.end('Footer\n');
}
}
function user(req,res) {
const username = req.url.replace("/","");
if (username.lenght > 0) {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.write('Header\n');
res.write(username + '\n');
res.end('Footer\n');
}
}
module.exports.home = home;
module.exports.user = user;
the first is in an example.js file and the second in the router.js fils
1 Answer
![Caroline olijve](https://secure.gravatar.com/avatar/465ebed3d654587f0651fdf84805bcf4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Caroline olijve
Courses Plus Student 14,499 PointsHi Sandro, I had the same problem , it is because the documentation has slightly changed and the copy-paste-example from node.js.org uses the setHeader-method. You can set that method only once (with me this was a message in the console), and after I removed the res.setHeader from the user-function all works fine.
Alex Thomas
4,247 PointsAlex Thomas
4,247 Pointsyou may have the wrong target, can you post your code?