Express.js + MongoDB + JavaScript codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
This codebase was created to demonstrate a fully fledged fullstack application built with Express.js + MongoDB + JavaScript including CRUD operations, authentication, routing, pagination, and more.
We've gone to great lengths to adhere to the Express.js + MongoDB + JavaScript community styleguides & best practices.
For more information on how to this works with other frontends/backends, head over to the RealWorld repo.
- install npm
- make sure mongo is running
- define needed env vars
DATABASE_URI- the uri to the mongo database: mongodb://127.0.0.1:27017/somedbname (assuming mongo is running on localhost:27017)ACCESS_TOKEN_SECRET- the secret used for the JWT
- execute
node api/index.js- e.g.,
ACCESS_TOKEN_SECRET=xyzzy-plover-boom DATABASE_URI=mongodb://127.0.0.1:27017/test node api/index.js
- e.g.,
- A contrast_security.yaml config file should be present and configured appropriately.
- The contrast agent should be installed as a dependency.
- For developmental testing, linking to the local node-mono repo is useful.
- To enable perf use a command line like:
CSI_PERF_INTERVAL=10000 CSI_PERF=1 ACCESS_TOKEN_SECRET=xyzzy-plover-boom DATABASE_URI=mongodb://127.0.0.1:27017/somedb node --import @contrast/agent api/index.js- loads the agent with perf enabled, using a 10 second interval for writing the log.
- set up
locustper instructions in thescript-locust/README.md - run the request-generating script,
script-locust/locustfile.pyusinglocust -f script-locust/locustfile.py --headless -i 1.--headlessjust means don't use the web UI, i.e., pure command line-fspecifies the file (more TBD, exercising different aspects of the code)-i 1specifies 1 iteration.
- the agent writes
agent-perf.jsonlagent-perf.jsonlcan be analyzed using tools inscript-analysis/.summarize.mjswill summarize the data. it's primitive, but provides basic data.
All the routes are defined in the
src/routesfolder, and their corresponding controllers are implemented in thesrc/controllersfolder.
- Only one
access_token_secretis used for all the accounts registration and login. Drawback: data can be forged if this secret is leaked - Included array structures, e.g. list of comments in the article model and favorited articles in the user model. Drawback: not good for scalability
- Usernames are case-sensitive
