Starting template to build a Node.js RESTful API Service with code written in TypeScript
Inspired by the awesome boilerplate w3rec
Made by @whatsaaaa
This template should provide you with a ready to develop application with functioning authentication using JWT tokens.
You can find an example controller UserController to see how can you develop new endpoints and database tables.
Also this template will include database seeds and migrations for mysql User table.
Install Node.js and NPM
Install Yarn
Install MySQL database
If you want a different database, it is possible to change it later.
Download this repository on your machine. Configure package.json (change author, project name, project description etc.)
After that copy the .env.example
file and rename it to just .env
. In this file add your configuration informations such as database connection information.
Now you are ready to setup your application.
yarn run setup
This command will install all dependencies with yarn. After that it will migrate the database and seed some test data into it. When this command is completed your application is ready to use.
To start your application locally run next yarn script.
yarn start serve
This will start a local server using
nodemon
, which will watch for any file changes and will restart the server.
All scripts are defined in the package-scripts.js
file. Here we will list the most important and most used ones.
- Install all dependencies with
yarn install
.
- Run code quality analysis using
yarn start lint
.
- Run
yarn start serve
to start nodemon with ts-node, to serve the app.
- Run
yarn start build
to generate all JavaScript files from the TypeScript sources. - To start the builded app located in
dist
folder, useyarn start
- Run
typeorm migration:create -n <migration-file-name>
to create a new migration file. - Migrate your database by running
yarn start db.migrate
command - Revert your latest migration run
yarn start db.revert
- Drop database chema
yarn start db.drop
- Run
yarn start db.seed
to seed your seeds into the database