Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!