As we know Express is a Node.js web application Framework that provides a robust set of features to develop web and mobile applications. It also provides the instant development of Node-based Web Applications.
Now as a part of the learning process below is the list of steps we will follow to gain In-depth and practical knowledge of working with express.js.
Installation of Express.js is fast and easy. It can be installed in a number of different operating systems. The key installation steps are listed below.
(here all the files will be saved in a folder/dir which we will develop)
(JSON is an open standard file format, that uses human-readable text to store and transmit data objects consisting of attribute and array data types.)
In the next step install the Express framework globally using NPM so that it can be used to create our web application using Node Terminal.
The above command saves the installation locally in the node_modules directory.
Users can also create servers using express.js and in this step, we will create a server using Express, below is some required code that is written before creating a server for us.
Because in order to use express in our project in node we use “require”.
Now if we want to create a web application, we need to call the Express function, for which the code is given below.
Now finally, to create a server for us we need to use a method called “listen”, and we can create a port by it after it we will call Function and pass two parameters i.e, Request & Response.
And to check whether the server is running smoothly we will print a statement that tells us that server is running smoothly.
After the above step check in the cmd terminal whether expserver.js is running or not, by typing the below command in the terminal.
The following screenshot will be flashed in the terminal.
In this step, we will handle the request and response for our website/application so that whenever a user accesses our host-no. Or port-no. He would send a response from the server to the user with a message.
Also, the get request function will be used for which we will give a location for getting a request.
Type the code below for achieving the same:
Screenshot of the result after saving the above code given below.
Nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
To install Nodemon, type the below-given command in the terminal and run it.
Discover the most interesting topic