Express.js is a web application framework that is built on top of Node.js. It provides a minimal
interface with all the tools required to build a web application. Express.js adds flexibility to an
application with a huge range of modules available on npm that you can directly plug into Express as
per requirement.
Step 1: Create a .gitignore file
Add node_modules/ and .env in it as we don't want node modules to be pushed to GitHub and also
our secret keys to be publicly available.
Step 2: Add dependencies
You may use yarn or npm (I am using yarn here).
yarn add for dependencies
yarn add -D for dev dependencies
NOTE: We might add more later on... and discuss them as we move along. Also, the version may be
newer for you or some of the packages may be deprecated in the future. Also as we are using
typescript we require type-definitions (@types) of all dependencies we have added
The dependencies shown below are the basic ones I think are required for the server to be up and
running.
Step 3: Create tsconfig.json file and add the following
Configuring TypeScript
You might want to look at the official documentation providing more insights for configuring
TypeScript and study more parameters available and use according to your needs.
Step 4: Create the main file
Create an src folder in your directory and add an app.ts file with the following contents to get
your express server up and running.
Relative Path: src/app.ts
Step 5: Setting up running scripts
Add the following to the package.json file
Now run "yarn run dev " to start our server and voila we have our server up and running.
You should see this as your output in the terminal and dist/ directory should appear in your
project containing all the JavaScript code with ES6 syntax.
Also, there's a ts-node package that runs node server using
TypeScript files without any need to generate any JavaScript files.