I built this repo to learn how to make a rest api and server. It was created by following this tutorial, and has been expanded on to service the needs of a boilerplate project. I've also used inspiration from this awesome dev!
The different things you can do with this server:
- Controllers - deals with database read/write operations and logic.
- Models - define schemas of objects in collections the database.
- Routes - defines the API routing for controller functions.
- Middlewares - helper files, utils and methods. Basically anything that isn't done by a controller.
-
Clone repo and run
npm ito install all packages -
In the
server.jsfile, you can modify the database location and name on line 22 -
Run MongoDB locally with
brew services start mongodb-community
-
Add a
.envflie to the root directory when first cloning this project for storing environment variables -
Add a
JWT_SECRETto the.envfile -
Start the server with nodemon:
npm start. Currently the default port for the server is5000and this can be set in the.env. This is to prevent clashes when running the server and clients in dev locally. -
Restart running server by typing:
rs
start- starts the serverreset- deletes the node_modulesreinstall- deletes and then reinstalls the node_modulestest- runs all unit teststest:watch- watches for unit tests that have changed and reruns the test suite
POST:
{
"email": "",
"password": "" (at least 6 characters long and contain a lowercase letter, an uppercase letter, a numeric digit and a special character.)
} POST:
{
"firstName": "", (firstName is optional)
"lastName": "", (lastName is optional)
"email": "",
"password": "" (at least 6 characters long and contain a lowercase letter, an uppercase letter, a numeric digit and a special character.)
"password2": ""
"acceptedTerms": Boolean
}This route is activated when a user clicks the link in an email sent to then when creating a new account.
Allows a user to get a password reset code emailed to them.
POST:
{
"email": "",
"password": "",
"password2": "",
"code": "" (this will have been emailed to the user)
}Allows a user to get a password reset code emailed to them.
POST:
{
"email": ""
}Allows a user to delete their account.
POST:
{
"password": "",
"uniqueId": ""
} GET
External route to check if a token is valid