Skip to main content

Create Simple WebServer in 2 min with Node Js



✊Let's create a simple web server  on node Js, which responds on Get method.

Step: 1

Install Node if you haven't yet according to you os platform.

Install npm globally.

npm install -g 


Verify the version of node and npm to check proper installations.



Step: 2

Open your favourite editor, am using vs code, and create "server.js" file.


Step: 3

We need http module to create http web server, so require the module as below.

const { createServer } = require('http');
const PORT = '3080' | process.env.PORT;


createServer((req, res) => {

res.end('welcome to node server!')


}).listen(PORT, () => {
console.log('server running on port 3080')
})


Step: 4

Create dynamic Port value from the process or static value if it runs in local env and listen the server on that port using listen method.

Step: 5

Create server instance as "createServer" and handle the req and responses as you like in the braces block.

Step: 6

Run node server as , node server.js in your terminal.



And you are done! ✌ Give a hit using Curl to get some response from the server you have create now..


It gives you a quick start to explore more on server rendering...




Comments

Popular posts from this blog

Custom Logging on IBM API Connect (V5) - Datapower Gateway

In realtime situation of an IT services from development phases to production the all time lifesaver would be the proper "logging mechanism" in place,  to avoid stress in development lifecycle and chaos after moving our application or apis onto production.   Even I have got this situation in my project and I have implemented this common Logging requirement for one of the reputed banks a while ago, so i thought to share this, so you can tweak as per you requirements. As of now we have two major version in IBM API Connect like V5 and V2018, the major difference with these new version are gateways, so this policy can be applied on the V5 compatibility Gateways only. Here we go.. If we understand the internals of the API Connect, when the request lands on the data power gateway the request is parsed and stores required information of the api transaction from source ip address to target url and all the required transformation data for the analytics purpose of that context in conte