It is easy to run your own server nowadays. Nodejs, makes it look like a piece of cake.
Once you have installed Node, let’s try building our first web server.
Create web directory:
Let’s start by creating our server directory.
1 | $ mkdir nodejs-server |
Server js file
Once we changed to the nodejs-server directory,
1 | $ cd nodejs-server |
create a server.js with the following code:
1 | const http = require('http'); |
Now our server is ready to be created.
Run as node
This is it! All we have to do now is to run as a node file.
1 | $ node ./server.js |
Now our server is listening to port 3000 and welcomes you to AshKeys
Tip: When it comes to routing it is
expressthat comes at best!