Before you start writing any code, we want to make sure that you have a project folder set up correctly, with the proper folder structure to house all of the various files that you will be creating. Get started by creating a new folder for your project, and name it anything you like. Then, inside that folder, create additional folders to match the following structure:
/(project root) ---/helpers ---/controllers ---/public ------/css ------/img ------/js ------/upload ---/server ---/Views ------/layouts ------/partials
Each of these folders will contain important modules that we will write throughout the remainder of this chapter and this book.
You are going to need a package.json file for this project, and the easiest way to create one of these is by simply executing the following command from the root of the project folder:
$ npm init
Respond to each of the questions as you are prompted, or simply press Enter repeatedly to accept the default values. Now, let's install Express and its necessary dependencies via npm:
$ npm install express morgan body-parser cookie-parser method-
override errorhandler express-handlebars --save
This will install the Express framework in the node_modules folder and also add Express to the package.json file in the dependencies section. Note that at the time of writing this book, Express.js is in its 4.x.x versions. Here, as you can see, Express is a completely decoupled framework that doesn't come with a lot of packaged modules within itself. Instead, you can figure out the dependencies of your application and plug in and out of the application anytime. If you have been following Express development from the beginning, you must have noticed that these changes were introduced as a part of the Express 4.x.x versions. Prior to this version, Express used to come with a lot of built-in modules bundled within it. Here, the modules we install alongside Express are the various dependencies our application has when we start building the complete web application. We will discuss the use of each module in a later section of this chapter.