Monday, May 20, 2019

Express JS and Hello-world Program in Webstrom

Express JS 💬


  • We all heart about java,c ,c#,c++ languages and so on. less us get to know about these new technology details which are ruling today's programming world.  we should eagerly know about these things. yes, here we know about the a web application framework. Express JS 💥

  •    Express.js is the most popular choice when it comes to built a web application with Node.js . It also a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile apps. It facilitates the rapid development of Node based web applications. Following are some of the features of Express framework :-

↦ Allows to setup middle wares to respond to HTTP Requests.

↦ Defines a Routing table which is used to perform different actions based on HTTP Method and URL.

↦ Allows to dynamically render HTML Pages based on passing arguments.


Installing Express.js

You can install Express.js using npm. 


this command will install version of express.js globally on our machine. so that every Node.js application on our machine can use it.



Hello World Example


Following is a very basic Express app which starts a server and listen port 8081 for connection. This app responds with 'Hello World!! We Started Working on Express :)for requests to the homepage.

1. open the Webstrom -> create a new Project

2. There are few options , you select the Node.js Express App
  

3. Give a Project name as you wish. (In my case it was HelloWorldExpress).



4.  Create the helloworld.js javascript file and write the following code







5. Run the helloworld.js and observe the console first.
   



6. Now Open http://127.0.0.1:8082/ in any browser to see the following result:





Now see the Coding,





Code Explanation:


  1. In our first line of code, we are using the require function to include "express Module".
     2. Before we can start the express module, we need to make an object of the express module.

     3. Here we are creating a callback function. This function will be called whenever anybody browses to the root of our web application. it will be used to send the string 'Hello world!! We are started working on Express' to the web page.

     4. In the callback function, we are sending the string 'Hello world!! We are started working on Express' to the client. The "res" parameter is used to send content back to the web page. This "res" parameter is something that is provided by the "request" module to enable one to send content back to the web page.

     5. We are then using the listen to function to make our server application listen to client requests. 



Advantages of Express.js



  • Makes Node.js Web application development fast and easy
  • Easy to configure and customize.
  • Allows you to define an error handling middle ware.
  • Allows you to create REST API server.
  • Easy to connect with Databases such as mongoDB,MYSQL.


1 comment:

Webservices — C# 👩🏻‍💻

  Webservices — C# 👩🏻‍💻 There are a lot of definitions defined about web services. In simple terms, The Web service is any software syste...