{"id":20455324,"url":"https://github.com/alexmhack/expressjs-todo-list","last_synced_at":"2026-04-04T22:31:52.517Z","repository":{"id":42875493,"uuid":"256938789","full_name":"Alexmhack/ExpressJS-Todo-List","owner":"Alexmhack","description":"A simple todo list web app in ExpressJS","archived":false,"fork":false,"pushed_at":"2022-12-11T02:34:32.000Z","size":353,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-09T02:44:19.074Z","etag":null,"topics":["expressjs","getting-started","mongodb","simple-app","todolist","tutorial"],"latest_commit_sha":null,"homepage":null,"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/Alexmhack.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}},"created_at":"2020-04-19T07:21:06.000Z","updated_at":"2023-08-27T01:35:42.000Z","dependencies_parsed_at":"2023-01-26T14:15:17.627Z","dependency_job_id":null,"html_url":"https://github.com/Alexmhack/ExpressJS-Todo-List","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Alexmhack/ExpressJS-Todo-List","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alexmhack%2FExpressJS-Todo-List","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alexmhack%2FExpressJS-Todo-List/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alexmhack%2FExpressJS-Todo-List/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alexmhack%2FExpressJS-Todo-List/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alexmhack","download_url":"https://codeload.github.com/Alexmhack/ExpressJS-Todo-List/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alexmhack%2FExpressJS-Todo-List/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31416770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"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":["expressjs","getting-started","mongodb","simple-app","todolist","tutorial"],"created_at":"2024-11-15T11:18:34.985Z","updated_at":"2026-04-04T22:31:52.469Z","avatar_url":"https://github.com/Alexmhack.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExpressJS-Todo-List\nA simple todo list web app in ExpressJS\n\n\n## MongoDB Integration\nFor connecting Express app with MongoDB we will use [mongoose](https://www.npmjs.com/package/mongoose).\n\nAfter installing MongoDB, run the server by running `mongod` from **cmd** or **terminal**. Now connect Express with MongoDB by\nmaking a mongoose `connection`,\n\n**app.js**\n```\nconst mongoose = require('mongoose');\n\nmongoose.connect(process.env.DATABASE, {\n    useNewUrlParser: true,\n    useUnifiedTopology: true\n});\n\nmongoose.connection\n    .on('open', () =\u003e {\n        console.log('Mongoose connection open');\n    })\n    .on('error', err =\u003e {\n        console.log(`Connection error: ${err.message}`)\n    })\n```\n\n1. `useNewUrlParser` is the new url parser for MongoDB Nodejs driver and for activating it we need to specify it explicitly.\n2. `useUnifiedTopology` is the new topology engine which is how mongoose handles monitoring all the servers in a replica set or shared cluster.\n\nNotice the line `process.env.DATABASE`, this comes from [dotenv](https://www.npmjs.com/package/dotenv), to install this package run,\n`npm install --save-dev dotenv` and at the top of the **app.js** file add,\n\n```\nrequire('dotenv').config();\n```\n\nNow create a **.env** file in your root dir and add a variable, `DATABASE`,\n\n```\nDATABASE=mongodb://localhost:27017/todolist\n```\n\n**Make sure to ignore *.env* file in your repo.**\n\nNow run the express server again or save the file to restart the server and if mongodb is running you will see the message,\n**Mongoose connection open...** in your terminal.\n\n## Schema \u0026 Models\nIndexes in MongoDB help in efficient execution of queries. Without indexed in MongoDB, it has to perform a collection scan, that\nis to scan every **document** in a **collection** to select those documents that match the query scan. If an appopriate index exists\nfor a query then MongoDB can use the index to limit the number of documents to scan.\n\nFor creating a Schema using mongoose, refer to [docs](https://www.npmjs.com/package/mongoose)\n\nFor our todo list app, we can create a simple schema like this,\n\n**models/Todo.js**\n```\nconst mongoose = require('mongoose');\nconst Schema = mongoose.Schema;\n\nconst todoSchema = new Schema({\n    title: { type: String, index: true, default: 'Todo thing', trim: true },\n    description: { type: String, trim: true },\n    date: { type: Date, default: Date.now, index: true }\n});\n\nmodule.exports = mongoose.model('Todo', todoSchema);\n```\n\nIn above code, we are defining type of the fields(we already have validation) and also using `trim` method from mongoose schema which\nwill trim any whitespaces from the user input. At last we are exporting the compiled model from Schema.\n\nNow to let mongoose know about our schema model, we need to require this file in the **app.js** at the top or above the import for **index router**.\n\nFor listing all the todos stored in MongoDB, we can use `.find()` method of our model without any arguments,\n\n**routes/index.js**\n```\nconst mongoose = require('mongoose');\n\nconst Todo = mongoose.model('Todo');\n\n...\n    Todo.find()\n        .then(todos =\u003e {\n            res.render('index', { title: 'All todos', todos })\n        });\n```\n\nFor deleting a document, mongoose provides with methods like, `deleteOne` and for many `deleteMany`,\n\n```\n...\n    Todo.deleteOne({ _id: req.param.id }, function(err) { console.log(err) })\n        .then(() =\u003e res.redirect('/'));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmhack%2Fexpressjs-todo-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexmhack%2Fexpressjs-todo-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmhack%2Fexpressjs-todo-list/lists"}