Full-Stack Web Development with Vue.js and Node

(singke) #1
Building an Express Application Chapter 2

Introducing Express.js


Express.js is a minimalist server-side web framework for Node.js. It is built on top of
Node.js to make it easy to manage the Node.js server. The most important strength of


Express.js is that it makes the routing very, very easy. The robust API that it provides is
very easy to configure. It is easy to receive requests from the frontend and easy to connect


to the database. Express.js is also the most popular web framework for Node.js. It uses the


Model View Controller (MVC) design pattern, which we will be discussing later on in this
chapter.


Installing Express.js


We have already covered how to install node modules via npm. Similarly, we can install


Express.js via NPM using this command:


$ npm install express

This is an easy way to install node modules. But, while building an application, we're going


to need lots of different kinds of modules. We will also want to share these modules across


our multiple applications. Hence, to make a module available globally, we will have to
install it globally. For that, npm provides the option of adding -g when installing node


modules. So, now we can use:


$ npm install -g express

This will install Express.js globally, which allows us to use the express command across


multiple applications.


Creating an Express.js application


Now that we have installed Express.js, let's get started creating an application using


Express.js.


We will name our application express_app. Building an outline of an express application


is very simple using the express command. We can simply use:


$ express express_app
Free download pdf