{"id":24701729,"url":"https://github.com/hurricanemark/nodeexpresslogintemplate","last_synced_at":"2026-04-04T22:33:44.402Z","repository":{"id":42613119,"uuid":"510871611","full_name":"hurricanemark/NodeExpressLoginTemplate","owner":"hurricanemark","description":"A nodejs-express login template containing essential components for implementing the usual application login for local strategy.   For those who do not wish to start from scratch, this code contains detailed explanation of the layout and where modules are being implemented into the normal (starter) node-express framework. ","archived":false,"fork":false,"pushed_at":"2022-11-07T03:07:24.000Z","size":171,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T12:06:33.161Z","etag":null,"topics":["bcrypt","dotenv","ejs","express","express-flash","express-session","nodejs","nodemon","passport","passport-local"],"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/hurricanemark.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":"2022-07-05T19:36:44.000Z","updated_at":"2022-07-05T21:03:15.000Z","dependencies_parsed_at":"2023-01-22T10:01:03.779Z","dependency_job_id":null,"html_url":"https://github.com/hurricanemark/NodeExpressLoginTemplate","commit_stats":null,"previous_names":[],"tags_count":2,"template":true,"template_full_name":null,"purl":"pkg:github/hurricanemark/NodeExpressLoginTemplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FNodeExpressLoginTemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FNodeExpressLoginTemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FNodeExpressLoginTemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FNodeExpressLoginTemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hurricanemark","download_url":"https://codeload.github.com/hurricanemark/NodeExpressLoginTemplate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FNodeExpressLoginTemplate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31416776,"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":["bcrypt","dotenv","ejs","express","express-flash","express-session","nodejs","nodemon","passport","passport-local"],"created_at":"2025-01-27T05:25:19.492Z","updated_at":"2026-04-04T22:33:44.333Z","avatar_url":"https://github.com/hurricanemark.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Passsport.JS Local Session Strategy\n\nPassport uses `serializeUser` function to persist user data (after successful authentication) into session. Function `deserializeUser` is used to retrieve user data from session.\n\nFollow SessionStrategy [HERE](./public/README.md)\n\n## Common Application Login\n\nAlmost every application requires the login as the entry point.  This node project provides the bare mininum implmementation of node-epress-passport employing local strategy.  \n\nPassport is a compatible middleware for express that allows you to choose which authentication strategy to use.  Some of the common strategies are local, federated with Facebook and Google, OpenID, and OAuth providers.  Since this template only implements local strategy, further exploy of passport is encouraged.\n\nThe focus of this project is on middleware.  However, this is a good starting point for futher investment of your time in backend development (database integration, business logic and policy), or further improving the frontend.\n\nNote, your .env file should contain the following defines:\n\n```\nPORT=####\nNODE_ENV=development\nSESSION_SECRET=your secret\n```\n\n\u003cstrong\u003eGenerate a strong session secret from *crypto*\u003c/strong\u003e\n\n`node -e \"console.log(require('crypto').randomBytes(64).toString('hex'));\"`\n\nCopy the output to *.env* file.\n\n\u003cbr\u003e  \n\nFor more information on the makeup of the project, read file *package.json* and to find out how to start the application.  Currently, it is `npm run dev`.\n\nNote also, this template requires further database implementation if you wish to save session data on the server side.  Currently, session data in runtime memmory is wiped out if you restarted the server.  As you can guess, memmory leakage in connect.session() is a concern and should not be used in production environment.\n\n\n### Recommend further works\n\n1. Use express-validator to validate contraints\n\n2. Use cachable database to store session data\n\n3. Add [express dynamic strategy](https://www.npmjs.com/package/dynamic-passport-strategies) to activate/deactivate during runtime and enable cluster support by spreading the configuration across the multiple nodejs instances.\n\n### Getting Started\n\n1. Clone this repository\n\n2. Update local development environment \n\n    `npm install`\n\n3. Run the app\n\n    `npm run dev`\n\n### Sample output\n\n```\n\u003e nodeexpresslogintemplate@1.0.0 dev D:\\DEVEL\\NODEJS\\BrainUnscramblers\\NodeExpressLoginTemplate\n\u003e nodemon server.js\n\n[nodemon] 2.0.18\n[nodemon] to restart at any time, enter `rs`\n[nodemon] watching path(s): *.*\n[nodemon] watching extensions: js,mjs,json\n[nodemon] starting `node server.js`\nServer is running on port 9999\nRegistering for  [\n  {\n    id: '1657051407426',\n    name: 'foo',\n    email: 'foo@bar',\n    password: '$2b$10$d58uZ3ol2G1uK14NMZeqdunMRjEBR27PaUHdrlQZkjQs.VDZBHPFK'\n  }\n]\n```\n\n\u003cbr\u003e  \n\n\u003cstrong\u003eSnapshots\u003c/strong\u003e\n\n![register](./public/register.PNG)\n\n![login](./public/login.PNG)\n\n![Landing page](./public/homePage.PNG)\n\nLogging out will take you back to the login page.  Now, try to login with an invalid password and notice the express-flash message cirled in red below.\n\n![logout, then try an invalid password](./public/invalidLogin.PNG)\n\n\n\u003cbr\u003e   \n\n### Modules and dependencies\n\nThe followings modules are some essential components for implementing the usual application login.  It can be used as a template for those who wish to not start from scratch.  These module can be found listed in package.json file.  It is recommended that you should check with the NPM registry for throurough details on each named modules bellow.\n\n* [express](https://www.npmjs.com/package/express) module is a light weight server that is fast, unopinionated, web framework for node.  Together with nodejs is made up the popular framework by which additional modules can be extended.\n\n* [dotenv](https://www.npmjs.com/package/dotenv) module is used to store and retrieve secrets in .env file\n\n* [ejs](https://www.npmjs.com/package/ejs) module is an embedded javascript template used to simplify express views.  Files create under views folder should be named *.ejs\n\n* [express-flash](https://www.npmjs.com/package/express-flash) is an extension of connect-flash with the ability to define a flash message and render it without redirecting the request.  Implement in views/*.ejs files.\n\n* [express-session](https://www.npmjs.com/package/express-session) is used to create session middleware in the cookie retaining just the session ID.  The full session object must be saved on the server side and compared with client session ID for authentication.\n\n* [passport](https://www.npmjs.com/package/passport) is Express-compatible authentication middleware for nod.js.  Its sole purpose is to authenticate requests via an extensible set of plugins known as strategies. Passport does not mount routes or assume any particular database schema, which maximizes flexibility and allows application-level decisions to be made by the developer. The API is simple: you provide Passport a request to authenticate, and Passport provides hooks for controlling what occurs when authentication succeeds or fails.\n\n* [passport-local](https://www.npmjs.com/package/passport-local) is one of the  strategies for authenticating with a username and password.  This module lets you authenticate using a username and password in your Node.js applications. By plugging into Passport, local authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.\n\n\n### Build and Run Docker image\n\nGenerate a docker image so you can share development code on dockerhub.\n\n\u003cstrong\u003eBuild\u003c/strong\u003e\n\n`docker build -t hurricanemark/nodejslogintemplate:1.0 .`\n\n\u003cstrong\u003eList the docker image\u003c/strong\u003e\n\n`docker image ls`\n\n```\nPS D:\\DEVEL\\NODEJS\\BrainUnscramblers\\NodeExpressLoginTemplate\u003e docker image ls\nREPOSITORY                            TAG                                        IMAGE ID       CREATED          SIZE\nhurricanemark/nodejslogintemplate     1.0                                        f5eaaeef3571   43 seconds ago   961MB\n```\n\n\u003cstrong\u003eRun docker\u003c/strong\u003e\n\n`docker run -p5432:8080 f5eaaeef3571`\n\n```\nPS D:\\DEVEL\\NODEJS\\BrainUnscramblers\\NodeExpressLoginTemplate\u003e docker run -p 5432:8080 f5eaaeef3571                   \n\n\u003e nodeexpresslogintemplate@1.0.0 start /app\n\u003e node server.js\n\nWarning: connect.session() MemoryStore is not\ndesigned for a production environment, as it will leak\nmemory, and will not scale past a single process.\nServer is running on port 8080\n```\n\nTo access the running docker container, from the browser http://[your ip address]:5432","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fnodeexpresslogintemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhurricanemark%2Fnodeexpresslogintemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fnodeexpresslogintemplate/lists"}