{"id":16483918,"url":"https://github.com/kevinadhiguna/js-create-jwt","last_synced_at":"2026-04-20T10:33:13.961Z","repository":{"id":107677726,"uuid":"401323348","full_name":"kevinadhiguna/js-create-jwt","owner":"kevinadhiguna","description":"🔑 A JavaScript program to create a JSON Web Token (JWT), powered by jsonwebtoken library.","archived":false,"fork":false,"pushed_at":"2022-09-09T05:56:31.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-07T03:46:14.295Z","etag":null,"topics":["docker","docker-compose","jwt","jwt-authentication"],"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/kevinadhiguna.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":"2021-08-30T11:44:48.000Z","updated_at":"2022-01-02T00:37:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"20e8d263-684e-4471-9e49-0486ab16438e","html_url":"https://github.com/kevinadhiguna/js-create-jwt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kevinadhiguna/js-create-jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinadhiguna%2Fjs-create-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinadhiguna%2Fjs-create-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinadhiguna%2Fjs-create-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinadhiguna%2Fjs-create-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinadhiguna","download_url":"https://codeload.github.com/kevinadhiguna/js-create-jwt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinadhiguna%2Fjs-create-jwt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32043065,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["docker","docker-compose","jwt","jwt-authentication"],"created_at":"2024-10-11T13:15:23.081Z","updated_at":"2026-04-20T10:33:13.937Z","avatar_url":"https://github.com/kevinadhiguna.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ch2 align=\"center\"\u003eJavaScript - Create JWT 🔑\u003c/h2\u003e\n\n  \u003cp align=\"center\"\u003e\n    A JavaScript program to create a JSON Web Token (JWT), powered by \u003ca href=\"https://github.com/auth0/node-jsonwebtoken\"\u003ejsonwebtoken\u003c/a\u003e library.\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"JavaScript\" src=\"https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge\u0026logo=javascript\u0026logoColor=%23F7DF1E\" /\u003e\n  \u003cimg alt=\"JSON Web Token\" src=\"https://img.shields.io/badge/JWT-black?style=for-the-badge\u0026logo=JSON%20web%20tokens\" /\u003e\n  \u003cimg alt=\"NodeJS\" src=\"https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge\u0026logo=node.js\u0026logoColor=white\" /\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\n## 📚 Table of Contents\n\n1. [🧐 What is JWT ?](#-what-is-jwt-)\n2. [⚙️ Prerequisites](#%EF%B8%8F-prerequisites)\n3. [🧶 How to Run (using `Yarn`)](#-how-to-run-using-yarn)\n4. [🐋 How to Run (using `Docker`)](#-how-to-run-using-docker)\n5. [🌊 How to Run (pull from DockerHub)](#-how-to-run-pull-from-dockerhub)\n6. [🐳 How to Run (using `docker-compose`)](#-how-to-run-using-docker-compose)\n\n\u003cbr/\u003e\n\n## 🧐 What is JWT ?\n\nJWT stands for JSON Web Token that is used **to authenticate a user/session** to backend services and also to authenticate between backend services.\n\u003cbr/\u003e\n\u003cbr/\u003e\nA JWT consists of three parts:\n1) Header (Metadata of JWT which are usually encoding algorithm and token type)\n2) Payload (Data that are encoded in JWT, do not store any sensitive data)\n3) Signature (A random string that is generated by Header + Payload + Secret)\n\nThe signing algorithm which is usually HS256, utilizes the header, the payload, and the secret to generate a string named signature. The figure below illustrates the signing process :\n\u003cbr/\u003e\n\u003cbr/\u003e\n![JWT-signing-process](https://user-images.githubusercontent.com/43397636/131616759-9b8671b3-bdb6-4cb0-a77d-f7c31770e5e0.png)\n\u003cbr/\u003e\n(image from : [StackOverflow - What is secret key for JWT based authentication and how to generate it?](https://stackoverflow.com/questions/31309759/what-is-secret-key-for-jwt-based-authentication-and-how-to-generate-it))\n\nIn the server-side which stores the secret (used to generate a signature), the JWT verification process occurrs. The figure below gives an illustration :\n\u003cbr/\u003e\n\u003cbr/\u003e\n![JWT-verification-process](https://user-images.githubusercontent.com/43397636/131617109-7973a771-7045-4419-ae7e-300d986baa20.png)\n\u003cbr/\u003e\n(image from : [StackOverflow - What is secret key for JWT based authentication and how to generate it?](https://stackoverflow.com/questions/31309759/what-is-secret-key-for-jwt-based-authentication-and-how-to-generate-it))\n\nThe JWT from the client is decoded to a header and a paylaod. Then both of them are combined with the secret in the server-side to geenrate a test signature. As a result, if test siganture matches the original signature that comes within the JWT from the client, it is verified succesfully which means the JWT is valid. Otherwise, it's invalid and data probably have been modified.\n\nReferences :\n- [Lovia - JSON Web Token](https://about.lovia.life/docs/engineering/lovia-system-architecture/jwt/)\n- [StackOverflow - What is secret key for JWT based authentication and how to generate it?](https://stackoverflow.com/questions/31309759/what-is-secret-key-for-jwt-based-authentication-and-how-to-generate-it)\n\n\u003cbr/\u003e\n\n## ⚙️ Prerequisites\n\nPrerequisites means what you should prepare/have before diving into a project. You should have [NodeJS](https://nodejs.org/en/) installed in your laptop/computer.\n\nThis project was created and tested using NodeJS v14.17.5. Hence, NodeJS version 14.17.5 or above should work.\n\n\u003cbr/\u003e\n\n## 🧶 How to Run (using `Yarn`):\n\n1) Clone this repository : \u003cbr/\u003e\n```\ngit clone https://github.com/kevinadhiguna/js-create-jwt\n```\n\u003cbr/\u003e\n\n2) Install dependencies : \u003cbr/\u003e\n```\nyarn\n```\nor\n```\nnpm install\n```\n\u003cbr/\u003e\n\n3) Create environment variables (`.env` file) by copying `.env.example` file :\n```\ncp .env.example .env\n```\n\u003cbr/\u003e\n\n4) Generate secret and put it into `.env` file :\n```\nopenssl rand 64 | base64 # (linux/macOS users)\n```\nor\n```\nnode -e \"console.log(require('crypto').randomBytes(64).toString('base64'))\" # (all users)\n```\n\n\u003cbr/\u003e\n\n5) Generate a new JWT : \u003cbr/\u003e\n```\nyarn generate\n```\nor\n```\nnpm run generate\n```\n\u003c!--\nThe result will look like this : \u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"https://s9.gifyu.com/images/generate-jwt.png\" alt=\"generate-jwt.png\" border=\"0\" /\u003e\n--\u003e\n\u003chr/\u003e\n\u003cbr/\u003e\n\n## 🐋 How to Run (using `Docker`):\n\nYou can either choose to build docker image by yourself or pull the docker image from DockerHub.\n\nIf you want to build docker image:\n1) Clone this repository : \u003cbr/\u003e\n```\ngit clone https://github.com/kevinadhiguna/js-create-jwt\n```\n\n2) Build the docker image : \u003cbr/\u003e\n```\ndocker build -t js-jwt .\n```\n\nNote: you can replace `js-jwt` with docker image name that you want.\n\n3) Generate secret : \u003cbr/\u003e\n```\nopenssl rand 64 | base64 # (linux/macOS users)\n```\nor\n```\nnode -e \"console.log(require('crypto').randomBytes(64).toString('base64'))\" # (all users)\n```\n\nCopy the result (secret) so that you can paste it as `JWT_SECRET` value in the next command.\n\n4) Run the docker image : \u003cbr/\u003e\u003cbr/\u003e\nLet's say the secret is `w4KuiqUDzvjIFBA4jHpUfjAeOOCH1DHJOODHkGXBUYLtK0bnp26GDM6WQvRUZtu2pgp3WiL5oFgz6XoSN7Q4VA==`. Then pass it as the `JWT_SECRET` value.\n```\ndocker run -e JWT_SECRET=w4KuiqUDzvjIFBA4jHpUfjAeOOCH1DHJOODHkGXBUYLtK0bnp26GDM6WQvRUZtu2pgp3WiL5oFgz6XoSN7Q4VA== js-jwt\n```\n\u003c!--\nThe command above should give you result like this : \u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"https://s9.gifyu.com/images/docker-generate-jwt.png\" alt=\"docker-generate-jwt.png\" border=\"0\" /\u003e\n--\u003e\n\u003chr/\u003e\n\u003cbr/\u003e\n\n## 🌊 How to Run (pull from DockerHub):\n\nIf you want to pull the docker image from DockerHub, here are the steps:\n1) Pull the docker image:\u003cbr/\u003e\n```\ndocker pull kevinadhiguna/js-create-jwt:latest\n```\n\n2) Generate secret : \u003cbr/\u003e\n```\nopenssl rand 64 | base64 # (linux/macOS users)\n```\nor\n```\nnode -e \"console.log(require('crypto').randomBytes(64).toString('base64'))\" # (all users)\n```\n\nCopy the result (secret) so that you can paste it as `JWT_SECRET` value in the next command.\n\n3) Run the docker image : \u003cbr/\u003e\u003cbr/\u003e\nLet's say the secret is `w4KuiqUDzvjIFBA4jHpUfjAeOOCH1DHJOODHkGXBUYLtK0bnp26GDM6WQvRUZtu2pgp3WiL5oFgz6XoSN7Q4VA==`. Then pass it as the `JWT_SECRET` value.\n```\ndocker run -e JWT_SECRET=w4KuiqUDzvjIFBA4jHpUfjAeOOCH1DHJOODHkGXBUYLtK0bnp26GDM6WQvRUZtu2pgp3WiL5oFgz6XoSN7Q4VA== kevinadhiguna/js-create-jwt:latest\n```\n\u003c!--\nThe command above should give you result like this : \u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"https://s9.gifyu.com/images/docker-generate-jwt-2.png\" alt=\"docker-generate-jwt-2.png\" border=\"0\" /\u003e\n--\u003e\n\u003chr/\u003e\n\u003cbr/\u003e\n\n## 🐳 How to Run (using `docker-compose`):\n\n1) Clone this repository : \u003cbr/\u003e\n```\ngit clone https://github.com/kevinadhiguna/js-create-jwt\n```\n\n2) Generate secret : \u003cbr/\u003e\n```\nopenssl rand 64 | base64 # (linux/macOS users)\n```\nor\n```\nnode -e \"console.log(require('crypto').randomBytes(64).toString('base64'))\" # (all users)\n```\n\nCopy the result (secret) so that you can paste it as `JWT_SECRET` value in `.env` file.\n\n4) Run docker-compose : \u003cbr/\u003e\n```\ndocker-compose up\n```\n\u003c!--\nThe command above should give you result like this : \u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"https://s9.gifyu.com/images/dc.png\" alt=\"docker-compose-generate-jwt.png\" border=\"0\" /\u003e\n--\u003e\n\u003c!--\nEventually, if you want to remove the docker container created from the command above, you can run `docker-compose down`. It also deletes the docker network. \u003cbr/\u003e\u003cbr/\u003e\n\u003cimg src=\"https://s9.gifyu.com/images/dc-2.png\" alt=\"dc-2.png\" border=\"0\" /\u003e\n--\u003e\n\u003cbr/\u003e\n\n![Hello !](https://api.visitorbadge.io/api/VisitorHit?user=kevinadhiguna\u0026repo=js-create-jwt\u0026label=thanks%20for%20dropping%20in%20!\u0026labelColor=%23000000\u0026countColor=%23FFFFFF)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinadhiguna%2Fjs-create-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinadhiguna%2Fjs-create-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinadhiguna%2Fjs-create-jwt/lists"}