Skip to content

Latest commit

Β 

History

History
81 lines (52 loc) Β· 3.84 KB

README.md

File metadata and controls

81 lines (52 loc) Β· 3.84 KB

Server – ExpressJS Backend

This ExpressJS template provides the basic infrastructure for a JSON API with MongoDB persistency with Mongoose. Despite the migration to a newer version of the Vue.js framework (i.e., the client part), the backend is still based on the original template.

Server Structure

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.

Requirements

  • Node.js (v18) => 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

Project setup

Make sure, you are in the server directory cd server

Installs all project dependencies specified in package.json.

npm install

Start the server with auto-restarts for development

Automatically restarts your server if you save any changes to local files.

npm run dev

Start the server

npm start

Run the Postman Tests

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.

Postman Tests

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 sure npm test succeeds for your final submission!

Error Handling

Debugging with VSCode

  1. Set a breakpoint by clicking on the left side of a line number
  2. Click Run > Start Debugging (Choose the "Debug Server" config if you opened the combined workspace)

Learn more in the VSCode Debugging Docs.