{"id":26347270,"url":"https://github.com/survi218/express-basic-auth","last_synced_at":"2026-04-13T14:31:15.107Z","repository":{"id":139643041,"uuid":"93576203","full_name":"survi218/express-basic-auth","owner":"survi218","description":"Express server to handle basic authentication","archived":false,"fork":false,"pushed_at":"2017-06-07T01:47:56.000Z","size":2140,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-07T20:46:36.477Z","etag":null,"topics":["base64","basic-authentication","express-middleware","expressjs","mongodb","mongoose","nodejs-modules","rest-api","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/survi218.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-06-07T00:49:10.000Z","updated_at":"2020-03-22T19:09:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"a4d27c46-ce71-495e-abf1-07ab8926ef21","html_url":"https://github.com/survi218/express-basic-auth","commit_stats":null,"previous_names":["survi218/express-basic-auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/survi218/express-basic-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fexpress-basic-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fexpress-basic-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fexpress-basic-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fexpress-basic-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/survi218","download_url":"https://codeload.github.com/survi218/express-basic-auth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fexpress-basic-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31757477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T13:27:56.013Z","status":"ssl_error","status_checked_at":"2026-04-13T13:21:23.512Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["base64","basic-authentication","express-middleware","expressjs","mongodb","mongoose","nodejs-modules","rest-api","server"],"created_at":"2025-03-16T07:16:25.887Z","updated_at":"2026-04-13T14:31:15.087Z","avatar_url":"https://github.com/survi218.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-basic-auth\n* Note:In the real-time projects we don't use 'base64' to encode/encrypt the username and password, which is not secured. \n* Using basic authentication approach to authenticate users. \n  - Set up an Express server to handle basic authentication\n  - Use the basic access authentication approach to do basic authentication.\n# Setting up the Express Server\n - Create a folder named basic-auth and then create package.json and server.js files.\n - Then go to the basic-auth folder and install all the node modules by typing the following at the prompt:\n\n````\n     npm install\n````\n * Open the server.js file write the code as follows:\n\n`````\nvar express = require('express');\nvar morgan = require('morgan');\nvar hostname = 'localhost';\nvar port = 3000;\nvar app = express();\napp.use(morgan('dev'));\nfunction auth (req, res, next) {\n    console.log(req.headers);\n    var authHeader = req.headers.authorization;\n    if (!authHeader) {\n        var err = new Error('You are not authenticated!');\n        err.status = 401;\n        next(err);\n        return;\n    }\n    var auth = new Buffer(authHeader.split(' ')[1], 'base64').toString().split('\n      :');\n    var user = auth[0];\n    var pass = auth[1];\n    if (user == 'admin' \u0026\u0026 pass == 'password') {\n        next(); // authorized\n    } else {\n        var err = new Error('You are not authenticated!');\n        err.status = 401;\n        next(err);\n    }\n}\napp.use(auth);\napp.use(express.static(__dirname + '/public'));\napp.use(function(err,req,res,next) {\n            res.writeHead(err.status || 500, {\n            'WWW-Authenticate': 'Basic',\n            'Content-Type': 'text/plain'\n        });\n        res.end(err.message);\n});\napp.listen(port, hostname, function(){\n  console.log(`Server running at http://${hostname}:${port}/`);\n});\n`````\n\n* Save the changes and start the server. Access the server from a browser and see the result\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurvi218%2Fexpress-basic-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurvi218%2Fexpress-basic-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurvi218%2Fexpress-basic-auth/lists"}