Node-js
How to Download & Install Node.js and NPM on Window
To start building your Node.js applications, the first step is the installation of the node.js...
The Node.js framework is mostly used to create server-based applications. The framework can easily be used to create web servers which can serve content to users.
There are a variety of modules such as the "http" and "request" module, which helps in processing server related requests in the webserver space. We will have a look at how we can create a basic web server application using Node js.
Let's look at an example of how to create and run our first Node js application.
Our application is going to create a simple server module which will listen on port no 7000. If a request is made through the browser on this port no, then server application will send a 'Hello World' response to the client.
Code Explanation:
If the command is executed successfully, the following Output will be shown when you run your code in the browser.
Output:
From the output,
Here is the code for your reference
var http=require('http') var server=http.createServer((function(request,response) { response.writeHead(200, {"Content-Type" : "text/plain"}); response.end("Hello World\n"); })); server.listen(7000);
Making a GET Request to get the data from another site is relatively very simple in Node.js. To make a Get request in the node, we need to first have the request module installed. This can be done by executing the following line in the command line
npm install request
The above command requests the Node package manager to download the required request modules and install them accordingly.
When your npm module has been installed successfully, the command line will show the installed module name and version: <name>@<version>.
In the above snapshot, you can see that the 'request' module along with the version number 2.67.0 was downloaded and installed.
Now let's see the code which can make use of this 'request' command.
Code Explanation:
Here is the code for your reference
var request = require("request"); request("http://www.google.com",function(error,response,body) { console.log(body); });
Summary
To start building your Node.js applications, the first step is the installation of the node.js...
What is GraphQL? GraphQL is an application layer server-side technology which is developed by...
Introduction to Node.js The modern web application has really come a long way over the years with...
Mostly all modern-day web applications have some sort of data storage system at the backend. For...
What is GraphQL? GraphQL is an application layer server-side technology which is developed by...
Bluebird is a fully-featured Promise library for JavaScript. The strongest feature of Bluebird is...