Core Backend in NestJS and MongoDB for Project Kampong.
-
Set up database. Refer to this guide on creating a MongoDB cluster on Atlas.
NB: After creating the cluster, take note of the cluster's Connection String.
NB2: Skip this step if setting up with VSCode Dev Container.
-
Set up config variables
a. In the file
config/sample.env, duplicate the file and rename it toconfig/config.env.b. Fill in all credentials required in the new file, as follows:
Variable Value NODE_ENV development / production PORT 5050 MONGO_URI Copy your MongoDB Connection String from previous step here.
(Skip if setting up with VSCode Dev Container) -
See App Setup to setup the app
There are 3 ways to setup the app
Recommended for development.
- Open repo in VSCode.
- VSCode will prompt to open the workspace in the remote container.
Folder contains a dev container configuration file. Reopen folder to develop in a container - Select
Reopen in container, VSCode will setup a fully ready environment. - Refer to the bottom left-hand corner of VSCode to verify that container is setup. It should have a text stating
Dev Container: Kampong Backend Core Development - To run app, see Running the app
NB: After changing env vars in
config/config.env, the devcontainer must be re-built:CMD+SHIFT+P> SelectRebuild and Reopen in Container
Recommended for quick setup. (Eg. to boot app quickly for testing with a frontend framework)
- Ensure
config/config.envis set up in your local repo. - Run
docker-compose up - App will setup and run automatically.
App requires the following dependencies to be installed locally (in the following order):
- NodeJS v16 (via nvm) To verify:
nvm -v - NestJS 7 (Optional) To verify:
nest -v
NB: NestJS installation is required for development. It is not required to run the app.
- Run
nvm install && nvm use - Verify node version with
node -v - Run
npm install - To run app, see Running the app
# development watch mode
$ npm run start:dev
# production mode
$ npm run start:prod# unit tests
$ npm run test
# test coverage
$ npm run test:cov