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

JavaScript Build a Simple Dynamic Site with Node.js HTTP Methods and Headers Perfection Suggestions

There was an error getting the profile for styles/main.css. (Not Found)

<!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">
    <link rel="stylesheet" href="./styles/main.css">
</head>
<body>

//Router JS

function style(req, res) {
    if (req.url.indexOf('.css') !== -1) {
        //console.log(req.url);
        res.writeHead(200, { 'Content-Type': 'text/css' });
        //console.log('test');
        renderer.css('main', res);
        //res.end();
    }
}

//Renderer.js
function css(templateName, response) {
    //Read from the template file
    //console.log(templateName);
    //console.log(res);
    try {
        var testContents = fs.readFileSync('./styles/main.css', { encoding: 'utf8' }); //console.log(testContents);
    } catch (error) {
        console.log('liamwears');
        console.log(error.message);
    }
    //console.log(testContents);
    response.write(testContents);
}
module.exports.css = css;

//app.js
const server = http.createServer((req, res) => {
    router.style(req, res);
    router.home(req, res);
    router.user(req, res);
});

Hi All, this has been a real nightmare for me so far. Ive had to do a lot of console logging to get this far. And now at least the page displays but I just keep getting the error listed in the Subject.

The error i am getting is There was an error getting the profile for styles/main.css. (Not Found) And the page does display but without any of the CSS styling.

If i uncomment the res.end(); from router.js i get the following error however the CSS initially works

events.js:174 throw er; // Unhandled 'error' event ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end

Please help this is driving me insane!