An Express/MongoDB API starter
A starter for creating an Express API using a MongoDB database.
After following the installation instructions in the root directory, do the following in this directory:
-
Clone the
.env.examplefile to create.env.developmentand.env.productionfiles.These will contain the environment variables for development and production environments.
-
Create a new account on mLab.
At this point, you will want to create two databases: one for development and one for production. I recommend naming them
*-devand*-prod, where*is the name of your app.Then, create new users for the databases. These will be the user that
mongoosewill use to connect. -
Add your mLab database information to the
envfiles.Each of your databases will have a unique standard MongoDB URI (visible at the top of a database's page on mLab). You can deconstruct them and add to your
envfiles as follows:mongodb://<MONGO_USERNAME>:<MONGO_PASSWORD>@<MONGO_URI>
-
Run
nvm useto ensure you're using the correct version of Node -
Run
npm startto start up the API development serverYou should now be able to visit the API at http://localhost:3001/api/v1 and begin development!
Note: if at any time you would like to cancel the running server instance, press
CTRL + Cin the open terminal window.
Don't commit messy code!
Here's a list of things already configured to keep you in line:
All of these tools will be run with the pre-commit hook (configured with Husky) to make sure you're not committing inconsistent code. We highly recommend configuring your editor to use these tools so that you can see (and fix) style violations as you write code.