I am starting a series on node js. Actually I’m not super skilled with node js. So I thought let’s start from zero again and help others with me to learn about it. I saw the ‘the net ninja’ tutorials and took the syllabus from there and make a fusion of my own. I want to help you with my journey, let’s ride together into node js for 30 days…

Day 12 — Creating own server— Learning Node JS In 30 Days [Mini series]

A full series to learn the basics easily of node js

Muhammad Ali
3 min readDec 15, 2019

--

Client make a request to the server and server provide the files using socket. So we are going to learn about how to make our own server using node today!

We are going to use http module for this. You can find the offical document here https://nodejs.org/dist/latest-v12.x/docs/api/http.html

First we are going to require http and store it to http variable using const http = require('http')

We are going to use http.createServer for creating the server

We can just start our server using const server = http.createServer() but there are some more work to do.

We need to write a function inside the createServer() so that we can get the request and response according about it

Now we can send data to request using res.end('Hey everyone!') and we need to give a port to listen. In my case I’m using 3000.

Now run the code using node app.js

and finally go to localhost:3000 and you can see the result

So do you learn something new from today ?

Originally it published on nerdjfpb blog and graphical version on instagram. you can connect with me in twitter, linkedin or instagram

--

--

Muhammad Ali
Muhammad Ali

Written by Muhammad Ali

An otaku who loves computer. Love to write and help others through my work. Have a look on my Instagram https://www.instagram.com/nerd_jfpb/

No responses yet