A sample API to develop a mobile application.
- Node.js 10.14+
- A running MongoDB 3.2+ database (see the Configuration section)
Clone this repository:
git clone [email protected]:sysin/comem-travel-log-api.git
Install dependencies:
cd comem-travel-log-api
npm ci
npm run dev
NODE_ENV=production npm start
Start by forking this repository. This will create a copy of the project on which you will have complete admin privileges.
You can fork by pressing the "fork" button at the top left of this page, or by clicking this link.
If you haven't yet created a MongoDB Atlas Cluster, follow the instructions from this guide: Create a MongoDB cluster on MongoDB Atlas
Follow the instructions in the Deploy the application to Render guide, but by taking into account the following differences:
- The build command is
npm ci
- You can setup your environment variables before deployment by clicking the advanced button. You will need to set two variables:
DATABASE_URI
: contains the connection information to your MongoDB Atlas Cluster. It should look a little something like this:mongodb+srv://<username>:<password>@<host>/?retryWrites=true&w=majority
SECRET
: a string of your choice used for generating JWT tokens.
The following environment variables can be used to customize the server:
Environment Variable | Default Value | Description |
---|---|---|
BASE_URL |
http://localhost:<PORT> |
The base URL at which the API is deployed. |
BCRYPT_COST |
10 |
bcrypt cost factor. |
DATABASE_URI , DATABASE_URL , MONGODB_URI , MONGODB_URL |
mongodb://localhost/comem-travel-log-api |
The URL used to connect to the database. The 4 variables are listed from highest to lowest precedence. |
DOCS_BROWSER |
Development option: which browser application to open the API documentation in. | |
DOCS_OPEN |
true |
Development option: whether to open the API documentation in the browser automatically when running npm run dev or npm run docs:serve . |
DOCS_PORT |
Random port | Development option: port on which to serve the API documentation when running npm run dev or npm run docs:serve . |
LOG_LEVEL |
info |
Log verbosity. Available levels are: trace , debug , info , warn , error , fatal . |
PORT |
3000 |
Port (or pipe) to bind the server to. |
SECRET |
Secret used to sign JWT tokens. |
Since dotenv is used, you can also set these variables using a .env
file:
PORT=4000
SECRET=changeme
The following scripts can be used to perform useful tasks:
Script | Description |
---|---|
npm run dev |
Build the API documentation, start the server in development mode with live reload and watch the documentation for changes. |
npm run docs:build |
Build the API documentation. (Run by npm run dev and after npm install .) |
npm run docs:clean |
Erase the API documentation. (Run by npm run dev .) |
npm run docs:serve |
Serve the API documentation on a local port with live reload, optionally open a browser. (Run by npm run dev .) |
npm run docs:watch |
Watch the source code for changes to automatically rebuild the API documentation. (Run by npm run dev .) |
npm run doctoc |
Regenerate this README's table of contents. |
npm start |
Start the server without live reload. |
npm run start:dev |
Start the server with live reload. |