{"id":19612515,"url":"https://github.com/murraco/node-jwt","last_synced_at":"2025-04-27T22:34:08.171Z","repository":{"id":42225688,"uuid":"112093656","full_name":"murraco/node-jwt","owner":"murraco","description":"JWT auth service with refresh using Node.js, ES6, Express, Sequelize and Mocha","archived":false,"fork":false,"pushed_at":"2025-02-19T14:41:07.000Z","size":969,"stargazers_count":29,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T04:31:49.936Z","etag":null,"topics":["authentication","es6","express","jwt","mocha","node","sequelize"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/murraco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"murraco","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2017-11-26T15:23:57.000Z","updated_at":"2025-02-19T14:41:04.000Z","dependencies_parsed_at":"2024-04-10T12:25:55.315Z","dependency_job_id":"37d8dadd-c9b8-4b02-b56f-9da9e67e4e90","html_url":"https://github.com/murraco/node-jwt","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/murraco%2Fnode-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murraco%2Fnode-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murraco%2Fnode-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/murraco%2Fnode-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/murraco","download_url":"https://codeload.github.com/murraco/node-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219600,"owners_count":21554444,"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":["authentication","es6","express","jwt","mocha","node","sequelize"],"created_at":"2024-11-11T10:46:58.217Z","updated_at":"2025-04-27T22:34:03.152Z","avatar_url":"https://github.com/murraco.png","language":"JavaScript","readme":"# Node JWT\n\n![](https://img.shields.io/badge/node-success-brightgreen.svg)\n![](https://img.shields.io/badge/test-success-brightgreen.svg)\n\n# Stack\n\n![](https://img.shields.io/badge/node_8-✓-blue.svg)\n![](https://img.shields.io/badge/ES6-✓-blue.svg)\n![](https://img.shields.io/badge/express-✓-blue.svg)\n![](https://img.shields.io/badge/sequelize-✓-blue.svg)\n![](https://img.shields.io/badge/mocha-✓-blue.svg)\n\n# File structure\n\n```\nnode-jwt/\n│\n├── api/\n│   ├── controllers/\n│   │   ├── AuthController.js\n│   │   └── UserController.js\n│   │\n│   └── models/\n│       └── User.js\n│\n├── config/\n│   ├── env/\n│   │   ├── development.js\n│   │   ├── index.js\n│   │   ├── production.js\n│   │   └── test.js\n│   │\n│   ├── routes/\n│   │   ├── validation/\n│   │   │   ├── auth.js\n│   │   │   └── user.js\n│   │   │\n│   │   ├── auth.js\n│   │   ├── index.js\n│   │   └── user.js\n│   │\n│   ├── express.js\n│   └── sequelize.js\n│\n├── test/\n│   ├── auth.test.js\n│   └── user.test.js\n│   \n├── .eslintrc                     * ESLint configuration file\n├── .gitignore                    * Example git ignore file\n├── index.js                      * Entry point of our Node's app\n├── LICENSE                       * MIT License\n├── package.json                  * Defines our JavaScript dependencies\n├── package-lock.json             * Defines our exact JavaScript dependencies tree\n└── README.md                     * This file\n```\n\n# Introduction (https://jwt.io)\n\nI have a great introduction to JWT in one of my other repositories, click [here](https://github.com/murraco/spring-boot-jwt#introduction-httpsjwtio) to take a look!\n\n## How to use this code?\n\n1. Make sure you have the latest stable version of Node.js installed\n\n```\n$ sudo npm cache clean -f\n$ sudo npm install -g n\n$ sudo n stable\n```\n  \n2. Configure your database and jsonwebtoken in `config/env`. E.g.:\n\n```javascript\nmodule.exports = {\n  mysql: {\n    host: 'localhost',\n    port: 3306,\n    database: 'jwt_dev',\n    username: 'root',\n    password: 'root',\n  },\n  jwt: {\n    jwtSecret: '$eCrEt',\n    jwtDuration: '2 hours',\n  },\n};\n```\n\n3. Fork this repository and clone it\n  \n```\n$ git clone https://github.com/\u003cyour-user\u003e/node-jwt\n```\n  \n4. Navigate into the folder  \n\n```\n$ cd node-jwt\n```\n5. Install NPM dependencies\n\n```\n$ npm install\n```\n  \n6. Make sure you have a MySQL DB up and running, if you don't, using docker is the easiest way\n\n```\n$ docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql\n```\nLogin into the container, update the root user and create databases\n\n```\n$ docker exec -it \u003cCONTAINER ID\u003e mysql -uroot -proot\n$ ALTER USER root IDENTIFIED WITH mysql_native_password BY 'root';\n$ CREATE DATABASE jwt;\n$ CREATE DATABASE jwt_dev;\n$ CREATE DATABASE jwt_test;\n```\n  \n7. Run the project\n\n```\n$ node index.js\n```\n  \n8. Or use `nodemon` for live-reload\n  \n```\n$ npm start\n```\n\n\u003e `npm start` will run `nodemon index.js`.\n  \n9. Navigate to `http://localhost:8000/api-status` in your browser to check you're seing the following response\n\n```javascript\n{ \"status\": \"ok\" }\n```\n\n\u003e The port can be changed by the setting the environment variable `PORT`\n\n10. If you want to execute the tests\n\n```\n$ npm test\n```\n\n\u003e `npm test` will run `mocha`.\n\n11. If you want to test it manually you can do it with the following commands\n\nRegister a new user:\n```\ncurl -X POST 'http://localhost:8000/users?username=admin2\u0026password=admin'\n```\n\nSign in with the new user credentials:\n```\ncurl -X POST 'http://localhost:8000/auth?username=admin\u0026password=admin'\n```\n\nCopy the token and send a request to get all current users:\n```\ncurl -X GET http://localhost:8000/users -H 'Authorization: Bearer \u003cJWT_TOKEN\u003e\n```\n\n12. And that's it, congrats! You should get a similar response to this one, meaning that you're now authenticated\n\n```json\n[\n  {\n    \"id\": 1,\n    \"username\": \"admin\",\n    \"createdAt\": \"2020-07-21T21:42:01.000Z\",\n    \"updatedAt\": \"2020-07-21T21:52:05.000Z\"\n  }\n]\n```\n\n# Contribution\n\n- Report issues\n- Open pull request with improvements\n- Spread the word\n- Reach out to me directly at \u003cmauriurraco@gmail.com\u003e\n\n# Buy me a coffee to show your support!\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/murraco)\n","funding_links":["https://ko-fi.com/murraco"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmurraco%2Fnode-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmurraco%2Fnode-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmurraco%2Fnode-jwt/lists"}