Skip to main content



ExpressJS

                  - Is a web application framework for Nodejs


                  - Discharged as free and open source computer program                              under the MIT Permit


                  - Is outlined for building web applications and APIs


                  - Provides a robust set of features for web and mobile                                     applications


                  - Developed ans maintained by the Node js foundation


                  - High performance, extensible and reusable 





How to start developing and using the Express Framework.



  • You should have the Node and the npm (node package manager) installed.
  • Confirm that node and npm are installed by running the following commands in terminal.

                          node --version
                          npm -- version


  • Start your terminal/cmd, create a new folder
  • Now to create the package.json file using npm
                           npm init

  • To install Express and add it to our package.json file, use the following command
                          npm install --save express

  • To make our development process a lot easier, we will install a tool from npm, nodemon. This tool restarts our server as soon as we make a change in any of our files
             npm install -g nodemon





Simple project using Express js

Print Hello world using Expressjs




var express = require('express');

var app = express();

app.get('/', function(req, res){
   res.send("Hello world!");
});

app.listen(3000);





Save the file, go to your terminal and type the following.

nodemon index.js




ExpressJS – Best Practices :

  • Always begin a node project using npm init.

  • Always install dependencies with a –save or –save-dev. This will ensure that if you move to a different platform, you can just run npm install to install all dependencies.

  • Stick with lowercase file names and camelCase variables. If you look at any npm module, its named in lowercase and separated with dashes. Whenever you require these modules, use camelCase.

  • Don’t push node_modules to your repositories. Instead npm installs everything on development machines.

  • Use a config file to store variables

  • Group and isolate routes to their own file. For example, take the CRUD operations in the movies example we saw in the REST API page.

Comments

Post a Comment

Popular posts from this blog

Restful Web Service Restful Web Service  is a lightweight, maintainable, and scalable service that is built on the REST architecture. Restful Web Service, expose API from your application in a secure, uniform, stateless manner to the calling client. Restful mostly came into popularity due to the following reasons: Heterogeneous languages and environments – This is one of the fundamental reasons which is the same as we have seen for  SOAP  as well. It enables web applications that are built on various programming languages to communicate with each other With the help of Restful services, these web applications can reside on different environments, some could be on Windows, and others could be on Linux. Restful Architecture An application or architecture considered REST full or REST-style has the following characteristics State and functionality are divided into distributed resources – This means that every resource should be accessible via ...
GitHub link  https://github.com/chamoddissanayake/OnlineFashionStore Group Project - Online Fashion Store There is a use case diagram of the system . This diagram denotes a better understanding about the system online fashion store. It provides who are the users of the system and what are the functionalities of the each user. System Functionalities Main Roles in the system. User Admin Store Manager Guest Only users who logged in to the system can place orders   Once the admin creates a login for the store manager, it should be notified to the store manager via email Admin can create categories for the products The store manager can add products with details to the relevant category and add discounts to selected products User can add products to the shopping cart   Users can purchase the selected products in the shopping cart by selecting the payment method Users can c...
          Application Framework Principles Frameworks In computer systems, a framework is generally a layered structure implying what kind of programs can or should be built and how they would interrelate. An Application Framework composed of a software framework used by software developers to implement the standard structure of application software. To give you an idea, let us consider the below scenario about the chassis of a car or the steel structure of a building. Application frameworks became famous with the growth of graphical user interfaces (GUIs) since these tended to promote a standard structure for applications. Developers usually use object-oriented programming (OOP) techniques to implement frameworks such that the unique parts of an application can simply inherit from classes extant in the framework.  Choosing a suitable framework among the available frameworks can be a tedious task. No...