You should make sure MongoDB is successfully running before proceeding (ie. guide for mac here)
In main directory:
Run $ npm install to download all dependencies (you'll likely want to do this every time you pull changes).
Running The Service
Run $ nodemon in the main directory to run the application (it will hot-reload upon file saves).
Then you can make HTTP requests to localhost:3000 -- the port is defined in .env
If you haven't done this before, using a tool like Insomnia is useful.
Running tests
Run $ npm test in the main directory
Note: We're using the jest testing framework. For HTTP requests, supertest is already a dependency if you want to use it.
Project Structure
The prod branch will be automatically deployed to prod.
So, it's best if you make a branch for your work, and then make a pull request
to the prod branch once your feature is done.
File Structure
/src/main.js is our main entry point.
Database:
/src/db/schema/ are schemas for our db objects.
/src/db/dao/ are db access objects -- ie. helper functions for making db calls. Ik these seem silly as we could make db calls directly from our code, but they're helpful for mocking db calls in our tests.
/src/db/db_factory.js returns db objects for our /src/db/dao/ files to use.
/src/.env is our dev env file. Variables here can be accessed in JS via process.env.VAR_NAME upon importing dotenv.
/tst/*.test.js are test files that correspond with a given src file.
The subdirectories within /src are specific features.
Node Specific files:
/src/package.json is where our dependencies are located
You should use npm commands to add/remove
dependencies rather than manually modifying it.
/src/node_modules is where our dependencies are stored. You shouldn't commit this folder
Examples for getting started:
Simple POST request that takes a JSON with a username field and returns it here. Note that to expose the routes, we have to add the files router to our app in main.js via: