Falah Al Fitri
Posted on December 19, 2019
This is next step from previous post
NodeJS http homepage 10: hello world
Falah Al Fitri ・ Dec 19 '19 ・ 1 min read
#node
#http
#helloworld
#beginners
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>' );
}
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>" );
}
for 404
page
else
{
res.writeHead( 404, { 'Content-Type': 'text/html' } );
res.write( '<h1>Page not found</h1>' );
}
and, close it
res.end();
💖 💪 🙅 🚩
Falah Al Fitri
Posted on December 19, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.