There is a no doubt that typescript is a life saver when it comes to large javascript project. Without being too much overwhelmed with lot of opinionated configuration, I thought I would publish a simple library which I have been using to bootstrap my nodeJS backend projects recently.
So the first command to start your project is
npx create-express-typescript-app hello-world
Here is the folder structure generated by this tool
Let’s go over the folders
- / — The root folder contains all the necessary files to setup the project, including the
typescript
configurations. If you are a NodeJS developer, these files should be familiar to you. - log — The project uses
morgan
dependency to log all access requests. It creates rolling file logger and a new file will be automatically generated everyday - src — This is where you are going to put all your
routes
,utils
,typings
and any otherts
andjs
files necessary for your project. To get started, sample routes and types are included in the template - public — If you decide to use express server for your static file hosting, it comes configured and assumes that
public
folder is your static file location. You can createhtml
,css
andjs
files in this folder and it will be automatically available over http(s)
Available commands
yarn start
— To start a development project. It keeps watching for changes insrc
folderyarn build
— Will generate compiled code. This command should be run before your project can serve in production.build
folder is required for production commands to run successfullyyarn prod-start
—pm2
has been very reliable tool to manage production node instances. This project comes pre-configured with this tool. This command will start your project in non-blocking mode.yarn prod-stop <id>
— This is the command to stop a running instance. You should pass<id>
to this command that you received from the previous command to start the app server.
I hope this is useful for those who are trying to find how to use both express and typescript in their projects.