This ExpressJS template provides the basic infrastructure for a JSON API with MongoDB persistency with Mongoose.
File | Purpose | What you do? |
---|---|---|
README.md | Everything about the server | READ ME carefully! |
app.js | JavaScript entry point for Express application | Import new routes/controllers |
controllers/ |
Implementation of Express endpoints | Define new route handlers |
models/ |
Mongoose models | Define data schema |
tests/server.postman_collection.json | Postman test scripts | Replace with your exported Postman test collection |
docs/FAQ.md | List of FAQs | Find answers to common questions |
docs/TROUBLESHOOTING.md | List of problems and solutions | Find solutions for common error messages |
package.json | Project meta-information | — |
NOTE: The (mandatory) exercises are essential for understanding this template and will save you time!
Optional: Learn how to create such a project template in this tutorial.
- Node.js (v14) => installation instructions for Linux, use installers for macOS and Windows (don't forget to restart your Bash shell)
- MongoDB (v4.4) must be running locally on port 27017 => installation instructions for macOS, Windows, Linux
- Postman (v8) for API testing
Make sure, you are in the server directory cd server
Installs all project dependencies specified in package.json.
npm install
Automatically restarts your server if you save any changes to local files.
npm run dev
npm start
Starts a new server on another port (default 3001
) and runs the server
postman test collection against a test database (default serverTestDB
).
npm test
The test database is dropped before each test execution. Adjust your tests to support this clean state.
We use the API testing tool Postman to define example HTTP requests and test assertions. Your tests will be automatically executed in GitLab pipelines whenever you push to the master
branch. Try to do that as often as possible.
Remember to export and commit any test changes back to
tests/server.postman_collection.json
and make surenpm test
succeeds for your final submission!
- Set a breakpoint by clicking on the left side of a line number
- Click Run > Start Debugging (Choose the "Debug Server" config if you opened the combined workspace)
Learn more in the VSCode Debugging Docs.