{"id":16629123,"url":"https://github.com/bradgarropy/node-express-pug-mongodb-server","last_synced_at":"2026-04-09T12:03:32.902Z","repository":{"id":93265976,"uuid":"96964150","full_name":"bradgarropy/node-express-pug-mongodb-server","owner":"bradgarropy","description":"Simple web server and REST API using Node, Express, pug \u0026 MongoDB.","archived":false,"fork":false,"pushed_at":"2017-08-03T03:02:19.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-09T19:02:48.525Z","etag":null,"topics":["express","expressjs","html","javascript","mongodb","mongoose","node","nodejs","pug","rest","rest-api","web-app","web-application","web-server"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bradgarropy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-12T04:09:23.000Z","updated_at":"2020-11-11T15:54:11.000Z","dependencies_parsed_at":"2023-08-25T08:01:59.419Z","dependency_job_id":null,"html_url":"https://github.com/bradgarropy/node-express-pug-mongodb-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bradgarropy/node-express-pug-mongodb-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradgarropy%2Fnode-express-pug-mongodb-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradgarropy%2Fnode-express-pug-mongodb-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradgarropy%2Fnode-express-pug-mongodb-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradgarropy%2Fnode-express-pug-mongodb-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradgarropy","download_url":"https://codeload.github.com/bradgarropy/node-express-pug-mongodb-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradgarropy%2Fnode-express-pug-mongodb-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268500608,"owners_count":24260163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","expressjs","html","javascript","mongodb","mongoose","node","nodejs","pug","rest","rest-api","web-app","web-application","web-server"],"created_at":"2024-10-12T04:39:42.792Z","updated_at":"2025-12-30T21:07:18.462Z","avatar_url":"https://github.com/bradgarropy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web Server \u0026 REST API Using Node, Express, pug \u0026 MongoDB\n\n*Learning about the world of JavaScript can be incredibly daunting.  \nLearning [Node](https://nodejs.org/) is even worse.*\n\nHere it is, the fourth and final iteration of the [node-only-server](https://github.com/bradgarropy/node-only-server) series! It's finally time to implement a proper data model and include a database into our project. As I wanted to reduce complexity, I decided to go with a NoSQL database. [MongoDB](https://www.mongodb.com/) seemed like the most popular choice, so I deployed a database on [mLab](https://mlab.com/home) and got to coding with [mongoose](http://mongoosejs.com/).\n\n\n## Lessons Learned\n\nAdding database support with [mongoose](http://mongoosejs.com/) was fairly easy and straightforward. I like the fact that I could define a schema for each collection and implement CRUD functionality quickly. Going through this process made me think about how to abstract the data model from the client as much as possible. To that end, I decided to implement date formatting using [Moment.js](http://momentjs.com/) directly in the [pug](https://pugjs.org/) template, as best practice seemed indicate that the database data types should be kept intact as long as possible.\n\nAfter finally improving the data model, I looked for other small improvements to make. I found that I was repeating a chunk of code for each HTTP request that logged the request method, parameters, and body. To follow the DRY principle, I converted that into an [Express](https://expressjs.com/) middleware function, and called it before every route. This piece of middleware only outputs the request body if it exists, and so here I got caught up figuring out how to do the simple task of checking if an object is empty in JavaScript. I gave in a realized the best solution was most likely in a library, and so I installed [lodash](https://lodash.com/) which solved my problem handily.\n\n\n## Conclusion\n\nAt this point I would call this exercise finished, but the project is far from complete! My goal is to turn this into a fully functional web application template. In that case, I should add a few more items:\n\n* User Registration\n* User Authentication\n* Restricted Pages\n* Front End Framework\n    * React\n    * Vue\n    * Angular\n\nAll these changes will be placed in the [nwa](https://github.com/bradgarropy/nwa) repository, so give it a star and follow along!\n\n\n## Project Iterations\n\n1. [node-only-server](https://github.com/bradgarropy/node-only-server)\n2. [node-express-server](https://github.com/bradgarropy/node-express-server)\n3. [node-express-pug-server](https://github.com/bradgarropy/node-express-pug-server)\n4. [node-express-pug-mongo-server](https://github.com/bradgarropy/node-express-pug-mongodb-server)\n\n\n## Features\n\nThis simple web application tracks weight measurements. It implements the following HTTP methods:\n\n* GET\n* POST\n* PATCH\n* DELETE\n\nIt also offers one page, the index, which shows the current weight entries.\n\n\n## Usage\n\nFirst, clone down the repository. Next, run the following command from inside the directory:\n\n`npm start` or `node server`\n\nIn order to access the index page, navigate to `localhost:3000` in your browser.\n\n\n## REST API\n\nUse your favorite REST client, mine is [Postman](https://www.getpostman.com/), to send requests to the server.\n\n### Retrieve Weight Entries\n```\nGET /api/weight\n```\n\n### Add Weight Entry\n```\nPOST /api/weight  \nParameters: { \"date\": \"2017-05-17\", \"weight\": 180 }\n```\n\n### Update Weight Entry\n```\nPATCH /api/weight/:date  \nParameters: { \"weight\": 180 }\n```\n\n### Remove Weight Entry\n```\nDELETE /api/weight/:date\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradgarropy%2Fnode-express-pug-mongodb-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradgarropy%2Fnode-express-pug-mongodb-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradgarropy%2Fnode-express-pug-mongodb-server/lists"}