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

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 create a wish list from their preferred
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 the normal HTT
React                -Is a java script library for build user interfaces.               -Used to create single page applications.               -Allows us to create reusable UI components.               -Every component in react goes through a life cycle of  events.               -Developed and maintained by Facebook and  Instagram.               -Acts as view in MVC architecture.               -Classes are considered as components.               -Simplicity and aim to performance are main benefits.                                              Main features in React (01)One way data flow Data flows parent component to child component only. But action flows from child component to parent component only. (02)Virtual DOM React maintain a virtual DOM. Continuously monitoring users actions. Only the changed element re enter. (03)JSX JavaScript XML. HTML like syntax. Prevents cross site attacks. -----------------------------------------