⚠️ This won't be updated anymore. You can find a port to Typescript here
Base code for an API based on Express
Clone this repo
~$ git clone git@github.com:iniva/express-api-base.git
To use your machine to run everything you will need:
-
Node LTS versions like Carbon or Dubnium(recommended). Using nvm is easy and recommended
-
Mac
- Run
brew install nvm
- Run
-
Ubuntu
- For the latest version check nvm releases
-
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash source ~/.profile
-
Both
Using lts/dubnium
- Run
nvm install lts/dubnium --latest-npm
to install the current LTS version of Node. Also, attempt to install the latest npm version - Run
nvm use lts/dubnium
to set Node to use this version - Run
yarn install
to install the project dependencies - Run
yarn start:development
to start the API see below for more options - By default the API will listen to http://0.0.0.0:8091
- Run
To use Docker Compose you will need:
-
On Mac: Get Docker for Mac
-
On Ubuntu: You will need to install Docker and then Docker compose
-
On the terminal, go to project's folder:
- Duplicate the file
.env.example
and rename it to.env
- Fill the available environment variables to your needs or leave them with their defaults
- To avoid permission conflicts between the host machine and the node container you need to change the UID values in the
.env
file.╰─$ id # uid=1000(username) gid=1000(username)
- Run
docker-compose build
to build the containers - Run
docker-compose up -d
to keep the process on background - Use
./run.sh server "{{command}}"
to start the server. e.g:╰─$ ./run.sh server "yarn start:development"
- Duplicate the file
Start API server in environment mode listening on port 8091
- Environments:
- development
- production
Remove build files
Generate build files (dist folder)
Generate (or update) the openapi.yaml
file.
Run the test suites
Run lint tool
Generate a new version tag. Also runs the build:docs
command to update the openapi.yaml
file with the new API version.
Helps you make commit messages using the project standardized format
I use this implementation to document the API.