Appendix: Express Setup on a Local Machine
Learn how to set up a Node and Express development environment on a local machine.
Express setup
In order to build a Node and Express application, we just need to initialize a Node environment and install a few npm
packages, as well as their corresponding
declaration files as follows:
mkdir node-express-app
cd node-express-app
npm init
npm install express
npm install @types/express --save-dev
We have created a directory named node-express-app
, changed into this
directory, and then initialized a Node environment with the npm init
command.
We then install the express
module using npm
and install the TypeScript declaration files for Express, as in @types/express
. We will also need to initialize a TypeScript environment within the same directory, which can be done as follows:
tsc --init
Compile and run
We can compile and run our newly minted Express web application as follows:
tsc
node minimal_app
Here, we are invoking the TypeScript compiler to compile our application and are then using the Node engine to execute the minimal_app.js
file. We will then see the following log on the console:
listening on port 3000
Installing the config
library
We can install the config
library using npm
as follows:
npm install config
We will also need the associated type information, which can be installed as follows:
npm install @types/config --save-dev
Installing Handlebars
Handlebars can be installed via npm
as follows:
npm install hbs
Installing the Bootstrap library
We can install the Bootstrap library as follows:
npm install bootstrap
Installing body-parser
package
We can install and configure a package named body-parser
as follows:
npm install body-parser
Installing the express-session
library
We can install and configure a package named express-session
as follows:
npm install express-session
npm install @types/express-session
Get hands-on with 1400+ tech skills courses.