{"id":22672733,"url":"https://github.com/jimlynchcodes/crud-lambda-typescript-mongo","last_synced_at":"2026-02-10T17:35:45.041Z","repository":{"id":41729259,"uuid":"234977788","full_name":"JimLynchCodes/CRUD-Lambda-TypeScript-Mongo","owner":"JimLynchCodes","description":"A little serverless lambda providing CRUD functionality for a MongoDB collection! 🎉 ","archived":false,"fork":false,"pushed_at":"2023-01-09T22:37:31.000Z","size":2748,"stargazers_count":2,"open_issues_count":27,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-04T17:56:14.851Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JimLynchCodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-19T22:30:57.000Z","updated_at":"2020-08-12T15:27:44.000Z","dependencies_parsed_at":"2023-02-08T15:16:09.104Z","dependency_job_id":null,"html_url":"https://github.com/JimLynchCodes/CRUD-Lambda-TypeScript-Mongo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JimLynchCodes/CRUD-Lambda-TypeScript-Mongo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2FCRUD-Lambda-TypeScript-Mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2FCRUD-Lambda-TypeScript-Mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2FCRUD-Lambda-TypeScript-Mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2FCRUD-Lambda-TypeScript-Mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JimLynchCodes","download_url":"https://codeload.github.com/JimLynchCodes/CRUD-Lambda-TypeScript-Mongo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2FCRUD-Lambda-TypeScript-Mongo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29309593,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T16:09:25.305Z","status":"ssl_error","status_checked_at":"2026-02-10T16:08:52.170Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-12-09T16:21:09.879Z","updated_at":"2026-02-10T17:35:45.021Z","avatar_url":"https://github.com/JimLynchCodes.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CRUD-Lambda-TypeScript-Mongo\n\nA little serverless lambda providing CRUD functionality for a MongoDB collection! 🎉 \n\n## Tldr;\n\nRun it with this command:\n```\nsls offline --skipCacheInvalidation --useSeparateProcesses start\n```\n\nThis is also aliased as the start command:\n```\nnpm start\n```\n\n## End-To-End Tests\nThe end-to-end tests have been automated with Postman!\n\nTo test manually -\u003e Import the `CRUD-Lambdas-TypeScript.postman_collection.json` into Postman!\n\nTo test from command line:\n```\nnpx newman run CRUD-Lambdas-TypeScript.postman_collection.json\n```\nor the npm command:\n```\nnpm run e2e\n```\n\n_Note: make sure your local mongoDb when running run End-to-end tests!_\n\n\n## Unit Tests\n\nUsing Mocha configured for typescript as the unit testing framework. \n\nTo run unit tests:\n```\nnpm test\n```\n\n_Note: you may need to run this command:_\n```\nnpm install -g ts-node\n```\n\n# Motivation\nAs a software engineer, I often find myself recreating a simple backend server that exposes CRUD (create, read, update, and delete) operations. In order to make my future developments faster I have created this project as somewhat of a reference guide.\n\n\n# Mongo \u0026 TypeScript\nThis \"CRUD Lambda\" project is written in _TypeScript_ and exposes CRUD operations for the _MongoDB_ database.\n\nTypeScript is an excellent superset of JavaScript that allows the written code to be explicitly about the types of objects and contains an experimental meant to make development more pleasant.\n\nMongoDB is a NoSql database that provides excellent querying \u0026 aggregation apis and fantastically balances speed and scalability.\n\n# What It Is\n\nThe goal of this project is to have a lambda function that exposes 5 endpoints relating to CRUD operations:\n\n- GET - /books # returns all books\n- GET - /books/:id # returns a book with id 1\n- POST - /books # inserts a new book into the table\n- DELETE - /books/:id # deletes a book with id of 1\n- PUT - /books/:id # updates a book with id of 1\n\nNotice that the endpoints in every case are consistent and plural (ie. books with an s). Following this practice is very common and highly recommended. \n\nOur Mongo Database will contain a collection of Books where each books has the same shape as this object:\n```\n{\n    \"title\": \"Clojure for the Brave and True\",\n    \"author\": \"Daniel Higginbotham\",\n    \"datePublished\": \"10/15/2015\",\n    \"pages\": 328\n}\n```\n\n# Pagination\nIn addition to the routes listed above, this project exposes an adiitional GET route with pagination. Though this will usually be the default behavior of the base slash route (`/books` in this case), I chose to make it a separate route in this case to illustrate how the implementation of the various routes differ.\n\nThe pagination route can be called like so:\n```\nhttp://localhost:3000/paginated-books/size=20\u0026after=someBookId\n```\n\nThis pagination implementation is \"cursor pagination\" whichi is slightly superior to \"offset-limit\" pagination because with cursor pagination the results are more what a user would when changing pages after inserting or deleting records from the collection.\n\n### A Nice Explanation of Cursor Pagination\n- https://jsonapi.org/profiles/ethanresnick/cursor-pagination/ \n\n### Example Implementations of \"Cursor Pagination\" With The MongoDb Mongoose Library\n- https://stackoverflow.com/a/21040304/1910355\n- https://stackoverflow.com/a/23640287/1910355\n\n\n# Usage\n\n## 0. Install Mongo Locally\nFollowing the guide [here](https://github.com/mongodb/homebrew-brew), I used brew:\n```\nbrew tap mongodb/brew\nbrew install mongodb-community@4.2\n```\n\nThen to use this as your default `mongodb-community` run this command:\n```\nbrew link mongodb-community\n```\n\nIf your mongo is out of control, you can track it down with this:\n```\nsudo lsof -iTCP -sTCP:LISTEN -n -P\n```\n\nand if you need to:\n```\nkill \u003cpid\u003e\n```\n\n\n### 1. Create the .env File\n\nFirst, copy the `.env_SAMPLE` file and rename it to `.env`:\n```\nmv .env_SAMPLE .env\n```\n\nEnter your mongo credentials in the .env file.\n\n\n### 2. Use Node v12\n\nIf you have nvm this command will use .nvmrc to switch to the correct node version:\n```\nnvm use\n```\n\n### 3. Install Dependencies\n```\nnpm i\n```\n\n### 4. Run Local Mongo\n```\nbrew start services mongo\n```\n\nFYI - to check if mongo is running:\n```\n\n```\n\nUse seed script to enter a few sample books into the collection.\n```\n./seed-db.sh\n```\n\n### 5. Execute Endpoints Locally\n\n#### Option B) With \"Serverless Invoke\"\n\n\n#### Option A) With \"Serverless Offline\"\n```\nsls offline start\n```\n\n#### Calling Endpoints From Postman (Manually)\n\n\n### 6. Run Unit Tests (Mocha)\n\n\n### 7. Run End-To-End Tests (Postman From Command Line)\n\n\n# Mongoose\nThis repo uses the mongoose library. Mongoose provides an \"ORM\" whereby you define models and use methods on them to interact with the database. This is nice because it makes it slightly hard to do the wrong thing. 😉\n\n\n# Shoutouts\n\nThis project was proudly scaffolded with the serverless cli:\n```\nsls create --template aws-nodejs-typescript\n```\n\nShoutout to [this excellent article](https://tutorialedge.net/typescript/typescript-mongodb-beginners-tutorial/) by [Elliot Forbes](https://twitter.com/elliot_f) which served as a great guide for me to follow and use for inspiration!\n\n\nShoutout to everyone I've ever worked with for shaping me to be the person I am today. 🙏\n\n\n# Contributing\nFeel free to open Issues or PR's if you have any comments or suggestions. ❤️\n\nAlso, feel free to tweet at me here: https://twitter.com/JimLynchCodes","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimlynchcodes%2Fcrud-lambda-typescript-mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimlynchcodes%2Fcrud-lambda-typescript-mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimlynchcodes%2Fcrud-lambda-typescript-mongo/lists"}