{"id":29416208,"url":"https://github.com/cristiancosta/node-ts-jwt","last_synced_at":"2026-01-20T16:28:12.366Z","repository":{"id":303615427,"uuid":"1008491402","full_name":"cristiancosta/node-ts-jwt","owner":"cristiancosta","description":"JWT authentication service made with Typescript, Node.js, Express and more.","archived":false,"fork":false,"pushed_at":"2025-08-26T11:55:12.000Z","size":1628,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-26T13:19:05.633Z","etag":null,"topics":["bcryptjs","eslint","express","husky","jest","jwt","mysql","nodejs","prettier","supertest","swagger","testcontainers","typeorm","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/cristiancosta.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,"zenodo":null},"funding":{"ko_fi":"cristiancosta"}},"created_at":"2025-06-25T16:14:52.000Z","updated_at":"2025-08-25T19:53:40.000Z","dependencies_parsed_at":"2025-07-08T14:50:01.327Z","dependency_job_id":"0714c191-af25-4df1-a3dc-0fcbfbcce310","html_url":"https://github.com/cristiancosta/node-ts-jwt","commit_stats":null,"previous_names":["cristiancosta/node-ts-jwt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cristiancosta/node-ts-jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristiancosta%2Fnode-ts-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristiancosta%2Fnode-ts-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristiancosta%2Fnode-ts-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristiancosta%2Fnode-ts-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cristiancosta","download_url":"https://codeload.github.com/cristiancosta/node-ts-jwt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristiancosta%2Fnode-ts-jwt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"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":["bcryptjs","eslint","express","husky","jest","jwt","mysql","nodejs","prettier","supertest","swagger","testcontainers","typeorm","typescript"],"created_at":"2025-07-11T19:02:05.285Z","updated_at":"2026-01-20T16:28:12.351Z","avatar_url":"https://github.com/cristiancosta.png","language":"TypeScript","funding_links":["https://ko-fi.com/cristiancosta","https://ko-fi.com/C0C81GYN0D"],"categories":[],"sub_categories":[],"readme":"# Node TS JWT\n\n![Test Status](https://img.shields.io/badge/Jest-tested-brightgreen?logo=jest)\n![Build Status](https://img.shields.io/badge/build-passing-success?logo=github)\n\n## 🧰 Stack\n\n[![TypeScript](https://img.shields.io/badge/language-TypeScript-3178c6?logo=typescript)](https://www.typescriptlang.org/)\n[![Node.js](https://img.shields.io/badge/Node.js-18%2B-green?logo=node.js)](https://nodejs.org/)\n[![Express](https://img.shields.io/badge/Express.js-5.x-black?logo=express)](https://expressjs.com/)\n[![JWT](https://img.shields.io/badge/JWT-secure-blue?logo=jsonwebtokens)](https://jwt.io/)\n[![TypeORM](https://img.shields.io/badge/TypeORM-ORM-red?logo=typeorm)](https://typeorm.io/)\n[![MySQL](https://img.shields.io/badge/MySQL-DB-4479A1?logo=mysql)](https://www.mysql.com/)\n[![Swagger](https://img.shields.io/badge/Swagger-UI-brightgreen?logo=swagger)](https://swagger.io/)\n[![Jest](https://img.shields.io/badge/Tested%20with-Jest-99425b?logo=jest)](https://jestjs.io/)\n[![Testcontainers](https://img.shields.io/badge/Testcontainers-Integration--Testing-green?logo=docker)](https://testcontainers.com/)\n[![Husky](https://img.shields.io/badge/Husky-Git%20Hooks-8e44ad?logo=git)](https://typicode.github.io/husky/)\n[![Supertest](https://img.shields.io/badge/Supertest-API%20Testing-blueviolet)](https://github.com/visionmedia/supertest)\n[![Prettier](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg?logo=prettier)](https://prettier.io/)\n[![ESLint](https://img.shields.io/badge/linting-eslint-yellow?logo=eslint)](https://eslint.org/)\n\n---\n\n## 🔐 Introduction\n\nThis is a REST API built with **TypeScript**, **Node.js** and **Express** that implements secure authentication using **JSON Web Tokens (JWT)**. It's a great base for systems that require login, user management, and access control via tokens.\n\nFeatures include:\n\n- 🔒 Authentication with **Access Token** and **Refresh Token**.\n- 📖 Interactive API documentation via **Swagger UI**.\n- 🧪 Real **MySQL** integration testing using **Testcontainers**.\n- ✨ **ESLint** + **Prettier** + **Husky** for code quality enforcement.\n- 🔁 **GitHub Actions** for automated CI/CD.\n\n---\n\n## 📁 Project Structure\n\n```\n├── .github/\n├── .husky/\n├── .vscode/                # Debuggers and workspace configuration.\n├── src/\n|   ├── controllers/        # Endpoint logic.\n|   ├── errors/             # Custom error classes.\n|   ├── middlewares/        # Auth, error handling, swagger auth.\n|   ├── models/             # Typeorm models.\n|   ├── repositories/       # Data access abstraction.\n|   ├── routes/             # Route definitions.\n|   ├── services/           # Business logic.\n|   ├── types/              # Data structure definitions.\n|   ├── utils/              # Reusable functions.\n|   ├── app.ts              # Express app configuration.\n|   ├── configuration.ts    # .env configuration entry point.\n|   ├── data-source.ts      # Typeorm configuration.\n|   ├── server.ts           # Entry point.\n|   └── swagger.ts          # Swagger configuration.\n├── test/                   # Unit and integration tests using jest, supertest and testcontainers.\n├── .gitignore              # Default gitignore file provided by GitHub.\n├── .prettierrc             # Prettier configuration file.\n├── eslint.config.mjs       # ESLint configuration file.\n├── jest.config.ts          # Jest configuration file.\n├── LICENSE                 # MIT License.\n├── package-lock.json       # Exact project dependencies tree.\n├── package.json            # Project dependencies, scripts and more stuff.\n├── README.md               # Current file.\n├── tsconfig.eslint.json    # ESLint typescript config file.\n└── tsconfig.json           # Project typescript config.\n```\n\n---\n\n## 🚀 Quick Installation\n\n```bash\ngit clone https://github.com/cristiancosta/node-ts-jwt.git\ncd node-ts-jwt\nnpm install\n```\n\nThen create a `.env` file in the project root with the following content:\n\n```env\nDB_HOST=localhost\nDB_USERNAME=root\nDB_PASSWORD=root\nDB_NAME=nodejwt\nDB_PORT=3306\n\nSERVER_PORT=8081\n\nJWT_SECRET=mysecret\nJWT_ACCESS_TOKEN_DURATION=2 hours\nJWT_REFRESH_TOKEN_DURATION=2 days\n\nSWAGGER_USERNAME=admin\nSWAGGER_PASSWORD=admin\n```\n\nMake sure you have a MySQL database up and running. In my case, I use Docker since it's the easiest way:\n\n```bash\n$ docker run -p 3306:3306 -e MYSQL_ROOT_USER=root -e MYSQL_ROOT_PASSWORD=root -d mysql\n```\n\nLog into the container and create the database:\n\n```bash\n$ docker exec -it \u003cCONTAINER ID\u003e mysql -uroot -proot\n$ CREATE DATABASE nodejwt;\n```\n\nStart the server:\n\n```bash\nnpm start\n```\n\n📍 The API will be available at: `http://localhost:8081`\n\n---\n\n## 📚 Interactive Documentation\n\nYou can explore and test all endpoints using Swagger UI:\n\n🔗 [http://localhost:8081/api-docs/](http://localhost:8081/api-docs/)\n\nBasic Auth required:\n\n- **Username:** `admin`\n- **Password:** `admin`\n\nYou can change Swagger credentials on `.env` file.\n\n---\n\n## 🧪 Testing with Testcontainers\n\nThis project uses **Testcontainers** to spin up a real MySQL instance during tests. This ensures:\n\n- A test environment **identical to production**.\n- No fragile mocks.\n- Automatic container cleanup.\n\nRun tests:\n\n```bash\nnpm test\n```\n\n---\n\n## ✅ Husky + Pre-commit hooks\n\nThe project uses **Husky** to automatically run the following before each commit:\n\n```bash\nnpx lint-staged  # Runs ESLint + Prettier\n```\n\n---\n\n## ⚙️ GitHub Actions CI\n\nThe project runs automated tests and perform building process on Node.js 20.x and 22.x via GitHub Actions.\n\n---\n\n## 🛠️ Useful Scripts\n\n| Command            | Description                                                   |\n| ------------------ | ------------------------------------------------------------- |\n| `npm start`        | Starts the server with Nodemon                                |\n| `npm test`         | Runs all tests using Jest + Testcontainers                    |\n| `npm run lint`     | Lints the code using ESLint                                   |\n| `npm run lint:fix` | Lints and auto-fixes issues                                   |\n| `npm run format`   | Formats code with Prettier                                    |\n| `npm run build`    | Builds the project with tsc                                   |\n| `npm run serve`    | Starts the server with Node (previous build script execution) |\n\n---\n\n## 🤝 Contributing\n\nContributions are welcome!\n\n1. Fork the repo.\n2. Create a new branch.\n3. Submit a Pull Request.\n4. Make sure lint and tests pass.\n\n📩 For direct contact: **cristiancosta1991@gmail.com**  \n🌟 Found it useful? Give the project a ⭐ on GitHub!\n\n[https://github.com/cristiancosta/node-ts-jwt](https://github.com/cristiancosta/node-ts-jwt)\n\n---\n\n## ☕ Donations\n\nIf you'd like to support this project, feel free to donate a coffee.\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/C0C81GYN0D)\n\n---\n\n## 📝 License\n\nMIT © [Cristian Costa](mailto:cristiancosta1991@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristiancosta%2Fnode-ts-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcristiancosta%2Fnode-ts-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristiancosta%2Fnode-ts-jwt/lists"}