{"id":14989737,"url":"https://github.com/juffalow/express-jwt-example","last_synced_at":"2025-04-12T00:32:03.989Z","repository":{"id":17744712,"uuid":"82074985","full_name":"juffalow/express-jwt-example","owner":"juffalow","description":"Example project for Express.js with JWT blogpost","archived":false,"fork":false,"pushed_at":"2023-01-23T18:06:38.000Z","size":54,"stargazers_count":32,"open_issues_count":5,"forks_count":20,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T05:11:05.681Z","etag":null,"topics":["chai","expressjs","jwt","mocha","nodejs","sinon"],"latest_commit_sha":null,"homepage":"https://juffalow.com/javascript/express-server-with-jwt-authentication","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/juffalow.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":"2017-02-15T15:25:01.000Z","updated_at":"2022-08-23T09:57:13.000Z","dependencies_parsed_at":"2023-02-13T01:46:14.453Z","dependency_job_id":null,"html_url":"https://github.com/juffalow/express-jwt-example","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/juffalow%2Fexpress-jwt-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juffalow%2Fexpress-jwt-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juffalow%2Fexpress-jwt-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juffalow%2Fexpress-jwt-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juffalow","download_url":"https://codeload.github.com/juffalow/express-jwt-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223486880,"owners_count":17153241,"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":["chai","expressjs","jwt","mocha","nodejs","sinon"],"created_at":"2024-09-24T14:18:50.817Z","updated_at":"2024-11-07T09:03:38.122Z","avatar_url":"https://github.com/juffalow.png","language":"JavaScript","readme":"# Express.js with JWT example\n\nThis is an example project to show how to create login route and some other\nroute that is protected - could be called only if valid JWT token is provided.\n\nEverything is well tested with [mocha](https://mochajs.org), [chai](http://chaijs.com), [sinon](http://sinonjs.org) and [supertest](https://github.com/visionmedia/supertest).\n\n## Dependencies\n\n* express\n* body-parser\n* jsonwebtoken\n* chai\n* mocha\n* sinon\n* supertest\n\n## Scripts\n\n`npm run start`\n\n`npm run test`\n\n## How to run the project\n\nInstall dependencies :\n\n```\nyarn install\n\n# or\n\nnpm install\n```\n\nEdit `config.example.js` and save it as `config.js` :\n\n```\nmodule.exports = {\n    port: 8080,\n    jwtSecret: 'your jwt secret'\n};\n```\n\nRun tests :\n\n```\nnpm run test\n```\n\nIf everything is OK, run the project :\n\n```\nnpm start\n```\n\n## How to test the project\n\nWhen you run the project, you should be able to load the URL `http://localhost:8080/`, but you shouldn't be able to access `http://localhost:8080/api/hello-world`.\n\nYou can log in by sending a post on `http://localhost:8080/login` and send there username and password, both set to _admin_.\n\n```\ncurl -XPOST -H \"Content-Type: application/json\" 'http://localhost:8080/login' -d '{\"username\":\"admin\",\"password\":\"admin\"}'\n```\n\nYou should get back something like :\n\n```\n{\n\"id\":1,\n\"username\":\"admin\",\n\"jwt\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNDg3NjM3OTg0LCJleHAiOjE0ODc2NDE1ODR9.1jMwROveQeR64baJOPdZV4SdpmKKVRvgPg0wJX9sHnI\"\n}\n```\n\nNow, when you want to load `http://localhost:8080/api/hello-world` and you send there `Authorization` header with _jwt token_ from the previous response, you should be successful :\n\n```\ncurl -XGET -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNDg3NjM3OTg0LCJleHAiOjE0ODc2NDE1ODR9.1jMwROveQeR64baJOPdZV4SdpmKKVRvgPg0wJX9sHnI' 'http://localhost:8080/api/hello-world'\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuffalow%2Fexpress-jwt-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuffalow%2Fexpress-jwt-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuffalow%2Fexpress-jwt-example/lists"}