DEV Community

Cover image for NodeJS http homepage 20: request url with link menu
Falah Al Fitri
Falah Al Fitri

Posted on

1

NodeJS http homepage 20: request url with link menu


Happy Coding

This is next step from previous post

In this post, we will add content home, about and 404 page with link menu using reg.url for checking

Ok, let's write on again.

for home page

    if ( req.url == '/' )
    {

        res.writeHead( 200, { 'Content-Type': 'text/html' } );

        res.write( '<h1>Hello World in NodeJS HTTP</h1>' );
        res.write( '<p>NodeJS easy-to-learn</p>' );        

    }
Enter fullscreen mode Exit fullscreen mode

for about page

    else if ( req.url == '/about')
    {

        res.writeHead( 200, { 'Content-Type': 'text/html' } );

        res.write( "<h1>About me</h1>" );
        res.write( "<p>I am developer</p>" );
        res.write( "<p>I love programming</p>" );        

    }
Enter fullscreen mode Exit fullscreen mode

for 404 page

    else
    {

        res.writeHead( 404, { 'Content-Type': 'text/html' } );

        res.write( '<h1>Page not found</h1>' );

    }
Enter fullscreen mode Exit fullscreen mode

and, close it

    res.end();
Enter fullscreen mode Exit fullscreen mode

Thank for reading :)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay