


Go to your terminal and hit the following command. Now we need to create a new file for our server code. Navigate into the new folder by running the command cd my-project. Then run the command mkdir my-project to create a new folder called my-project. There is one framework called express js. We will use express js to construct a server because it is made on top of the node.js framework provides various functionalities that can be very helpful to build a web application. Open a terminal or command prompt and navigate to the directory where you want to create your project folder. Go to can see that we got a response in plain text that says hello world. Great!! We have built a fundamental node.js server. As a default browser, I am using Google Chrome as it is most famous now. So as the terminal said, our node.js web application is running on port 3000.

When the browser hits the server, then in response, we will send plain text. So what I have done is use the built-in http module. Then, we have used its method createServer. It takes an argument as a req and res. Coupled with Node's purely evented infrastructure, it makes a. Node attempts to correct these problems in its HTTP parser and API. For example, streaming data through most web frameworks is impossible. This isn't recommended for use in production but is a great way to quickly get a server running on localhost. Node's HTTP library has grown out of the author's experiences developing and working with web servers.
NODEJS HTTP SERVER INSTALL
Var server = http.createServer(function(req, res) ) Simplest Node.js server is just: npm install http-server -g Now you can run a server via the following commands: cd MyApp http-server If you're using NPM 5.2.0 or newer, you can use http-server without installing it with npx. Inside the root folder, make one file called server.js. Okay, now go into that folder and open that folder in your editor, and in my case, it is code. Step 1: Create a project folder.įirst, create a folder using the following command. You can find more details on their website. So I highly recommend VSCode for the development. As an editor, I am using Visual Studio Code, and it has excellent support on Node.js as a platform.
