{"id":18614887,"url":"https://github.com/andrewjbateman/node-mongodb-zod","last_synced_at":"2026-04-09T18:41:59.812Z","repository":{"id":96860789,"uuid":"417556782","full_name":"AndrewJBateman/node-mongodb-zod","owner":"AndrewJBateman","description":":clipboard: Node.js app","archived":false,"fork":false,"pushed_at":"2022-01-11T11:34:22.000Z","size":159,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-27T02:44:52.296Z","etag":null,"topics":["express","expressjs","mongodb","mongodb-atlas","mongoose","nodejs","typescript","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/AndrewJBateman.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":"2021-10-15T15:54:39.000Z","updated_at":"2023-04-02T13:14:14.000Z","dependencies_parsed_at":"2023-04-12T19:47:33.015Z","dependency_job_id":null,"html_url":"https://github.com/AndrewJBateman/node-mongodb-zod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fnode-mongodb-zod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fnode-mongodb-zod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fnode-mongodb-zod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndrewJBateman%2Fnode-mongodb-zod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndrewJBateman","download_url":"https://codeload.github.com/AndrewJBateman/node-mongodb-zod/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239406449,"owners_count":19633024,"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","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","mongodb","mongodb-atlas","mongoose","nodejs","typescript","zod"],"created_at":"2024-11-07T03:27:19.639Z","updated_at":"2026-04-09T18:41:54.772Z","avatar_url":"https://github.com/AndrewJBateman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :zap: Node MongoDB Zod\n\n* Node.js + Express used with the [zod library](https://github.com/colinhacks/zod) to interract with a MongoDB database\n* **Note:** to open web links in a new window use: _ctrl+click on link_\n\n![GitHub repo size](https://img.shields.io/github/repo-size/AndrewJBateman/node-mongodb-zod?style=plastic)\n![GitHub pull requests](https://img.shields.io/github/issues-pr/AndrewJBateman/node-mongodb-zod?style=plastic)\n![GitHub Repo stars](https://img.shields.io/github/stars/AndrewJBateman/node-mongodb-zod?style=plastic)\n![GitHub last commit](https://img.shields.io/github/last-commit/AndrewJBateman/node-mongodb-zod?style=plastic)\n\n## :page_facing_up: Table of contents\n\n* [General info](#general-info)\n* [Screenshots](#screenshots)\n* [Technologies](#technologies)\n* [Setup](#setup)\n* [Features](#features)\n* [Status](#status)\n* [Inspiration](#inspiration)\n* [Contact](#contact)\n\n## :books: General info\n\n* Controllers: One for each resource: product, session and user\n* Middleware: there are three - to deserialize user, require user \u0026 validate resource\n* Models: one for each resource: product, session and user\n* Schema: used by validate resource middleware\n* Utils: utilities for connection to the database, jwt \u0026 logger\n* Data flow: HTTP endpoint \u003c-\u003e ( Middleware ) \u003c-\u003e Controller \u003c-\u003e Service \u003c-\u003e Database\n* [mongoose v6](https://mongoosejs.com/docs/migrating_to_6.html) legacy type HookNextFunction has been removed\n* [mongoose queries with the lean option](https://mongoosejs.com/docs/tutorials/lean.html) used to get results faster\n* [lodash omit](https://lodash.com/docs/4.17.15#omit) used to return a copy of the object minus the filtered item - user password in this case\n* [zod library](https://github.com/colinhacks/zod) used for data validation with automatic typing, as the code uses typescript data types\n\n## :camera: Screenshots\n\n![Image](./imgs/postman.png)\n\n## :signal_strength: Technologies\n\n* [Node.js v14](https://nodejs.org/) Javascript runtime using the [Chrome V8 engine](https://v8.dev/)\n* [Express v4](https://www.npmjs.com/package/express) web framework for node\n* [MongoDB Atlas](https://www.mongodb.com/es/cloud/atlas) cloud database service\n* [mongoose v6](https://mongoosejs.com/) mongodb object modelling for node.js\n* [pino v7](https://www.npmjs.com/package/pino) very low overhead Node.js logger.\n* [dayjs v1](https://www.npmjs.com/package/dayjs) minimalist JavaScript library that parses, validates, manipulates \u0026 displays dates and times\n* [zod v3](https://www.npmjs.com/package/zod) TypeScript-first schema declaration and validation library. A schema can be any data type\n* [JWT tokens](https://jwt.io/) using RS256 algorithm\n* [nanoid](https://www.npmjs.com/package/nanoid) A tiny (130bytes), fast (2x faster than UUID), secure, URL-friendly, unique string ID generator for JavaScript. ID size is only 21 symbols\n\n## :floppy_disk: Setup\n\n* `npm i` to install dependencies\n* Create `.env` and add database credentials - see `.example.env`\n* Create public \u0026 private keys using [JWT](https://jwt.io/) with the RS256 algorithm option selected. Take care with the format and the `-----END PRIVATE KEY----` etc. to avoid an \"ERR_OSSL_PEM_BAD_END_LINE\" error\n* MongoDB has to be running - I used the cloud database MongoDB Atlas instead of installing MongoDB on my hard drive\n* `yarn dev` or `npm run dev` runs app in the development mode with auto-restart.\n* Open [http://localhost:5000](http://localhost:5000) to view it in the browser.\n\n## :wrench: Testing\n\n* Postman and Thunder Client used to simulate HTTP endpoints\n* See `test.txt` for tests that have passed\n\n## :computer: Code Examples\n\n* Function to create new user to schema format; email, password, password confirmation \u0026 name strings\n\n```typescript\nexport const createUserHandler = async (\n  req: Request\u003c{}, {}, CreateUserInput[\"body\"]\u003e,\n  res: Response\n) =\u003e {\n  try {\n    const user = await createUser(req.body);\n    return res.send(user);\n  } catch (err: any) {\n    logger.error(err);\n    return res.status(409).send(err.message);\n  }\n};\n```\n\n## :cool: Features\n\n* [Nano ID](https://www.npmjs.com/package/nanoid) id generator uses 21 symbols and is only 130bytes. \n\n## :clipboard: Status, Testing \u0026 To-Do List\n\n* Status: Code complete and part tested\n* To-Do: Complete testing using Thunder Client\n\n## :clap: Inspiration\n\n* [TomDoesTech: Build a REST API with Node.js, Express, TypeScript, MongoDB \u0026 Zod](https://www.youtube.com/watch?v=BWUi6BS9T5Y\u0026t=198s)\n\n## :file_folder: License\n\n* N/A\n\n## :envelope: Contact\n\n* Repo created by [ABateman](https://github.com/AndrewJBateman), email: gomezbateman@yahoo.com","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewjbateman%2Fnode-mongodb-zod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewjbateman%2Fnode-mongodb-zod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewjbateman%2Fnode-mongodb-zod/lists"}