First Node-Express Web Server.

ExpressJs is a web application development framework for Node.js.Not only that express is used for web development in nodeJs there are other frameworks that you can use for web appliaction.

  • Express.Js
  • Hapi.Js
  • Koa.Js
  • Sails.Js

But we are going to create our first basic web server using expressjs

First lets create package.json by running this command npm init -y in your terminal.But please make sure nodejs must be installed in your machine https://nodejs.org/en/

coderuck-express

Once you run above command one package.json file will get created this is  responsible  for managing npm packages ,version etc.

In Second step we will install expressJs npm i express

Once you run the above command these files will get created automatically by npm 

coderuck-express

Folder node_module contain all the packages that you will install for your appliaction.

In Step 3 we will create one index.js in root file which contain following code for our first express web application.

coderunk-expres

In the above code we have used expressjs for our appliaction and then we have used express() object in app.

app.listen([port[, host[, backlog]]][, callback] which is responsible for running your application in any port which you will specify.

Now run your appliaction by running node index.js in CLI

coderuck-express

As you can see the console.log message that means you have successfully created your first basic node express web application.

In next example we will see expressJs in more detailed way.

 

Leave a reply

your email address will not be published. required fields are marked *

Name *
Email *
Website