{"id":24581460,"url":"https://github.com/aprilmintacpineda/nodejs-express-jwt-boilerplate","last_synced_at":"2026-05-03T01:43:55.655Z","repository":{"id":144013557,"uuid":"261144478","full_name":"aprilmintacpineda/nodejs-express-jwt-boilerplate","owner":"aprilmintacpineda","description":"Boilerplate for your NodeJs application using express and JWT.","archived":false,"fork":false,"pushed_at":"2020-05-04T12:24:58.000Z","size":88,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-30T14:43:24.285Z","etag":null,"topics":["boilerplate","expressjs","jsonwebtoken","jwt","nodejs"],"latest_commit_sha":null,"homepage":null,"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/aprilmintacpineda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-05-04T10:33:18.000Z","updated_at":"2020-05-04T12:25:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"65ccf666-d0e2-4014-8b7e-68f577d448fc","html_url":"https://github.com/aprilmintacpineda/nodejs-express-jwt-boilerplate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aprilmintacpineda/nodejs-express-jwt-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilmintacpineda%2Fnodejs-express-jwt-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilmintacpineda%2Fnodejs-express-jwt-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilmintacpineda%2Fnodejs-express-jwt-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilmintacpineda%2Fnodejs-express-jwt-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aprilmintacpineda","download_url":"https://codeload.github.com/aprilmintacpineda/nodejs-express-jwt-boilerplate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilmintacpineda%2Fnodejs-express-jwt-boilerplate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32555839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T00:31:16.350Z","status":"ssl_error","status_checked_at":"2026-05-03T00:31:15.546Z","response_time":132,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["boilerplate","expressjs","jsonwebtoken","jwt","nodejs"],"created_at":"2025-01-24T02:58:18.625Z","updated_at":"2026-05-03T01:43:55.633Z","avatar_url":"https://github.com/aprilmintacpineda.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nodejs-express-jwt-boilerplate\n\nBoilerplate for your NodeJs application using express and JWT with Web Socket using redis. This NodeJS web server is suppose to be **independent of the frontend**.\n\n# Getting started\n\n1. `git clone git@github.com:aprilmintacpineda/nodejs-express-jwt-boilerplate.git`.\n2. `cd nodejs-express-jwt-boilerplate`\n3. `rm -rf .git` -- you won't need to use that.\n4. `npm i` -- optionally, you can do `npm-check -u` to update the dependencies.\n\n## Generate JWT keys\n\n1. `cd src`.\n2. Don't add passphrase, `ssh-keygen -t rsa -b 4096 -m PEM -f jwt.key`.\n3. `openssl rsa -in jwt.key -pubout -outform PEM -out jwt.pub`.\n4. `rm -rf jwt.key.pub` -- remove the `jwt.key.pub` you don't need it.\n\n# Development\n\nYou can run `npm run dev` and start editing file on `src/`.\n\n# Production\n\nYou can run `npm run build` to build the `src` files.\n\n## Production TODOS check list\n\nAfter the machine has been set up, don't forget to do `sudo apt-get update`.\n\n### cls=clear\n\nFor your convenience, add `alias cls=clear` to `~/.bashrc`.\n\n- `cat ~/.bashrc`\n- `sudo echo \"alias cls=clear\" \u003e\u003e ~/.bashrc`\n- `source ~/.bashrc`\n- `cat ~/.bashrc`\n\n### Directories\n\n- `mkdir ~/Downloads`\n- `mkdir ~/Uploads`\n\n### Things to install on the machine\n\nThough nodejs has a built-in cluster capability, I suggest using `nginx` as reverse proxy, then you can use `pm2` and spin up a cluster listening to separate ports and then you can map those ports to `nginx` for load balancing.\n\n#### apt\n\n1. `sudo apt-get update`\n2. `sudo apt-get install --reinstall make g++ gcc zip tcl libpcre3-dev zlibc zlib1g zlib1g-dev libssl-dev -y`\n\n- `make`, and `g++` are need for `bcrypt` node module.\n- `gcc` and `tcl` are needed for redis' `make test`\n- `libpcre3-dev`, `zlibc`, `zlib1g`, `zlib1g-dev`, `libssl-dev` are needed for building nginx modules\n\nTo build nginx dynamic modules, you need to get the flags of the nginx using `nginx -V` and then add the `add-dynamic-module=/path/to/git/repo` flag.\n\n#### nginx\n\n[Follow install instructions](http://nginx.org/en/linux_packages.html#Ubuntu)\n\n#### Setting up nginx\n\n##### Enable gzip\n\nOn http block on `/etc/nginx/nginx.conf`:\n\n```\ngzip  on;\ngzip_types text/plain application/xml application/json text/javascript text/css application/javascript;\n```\n\n##### Security\n\nOn http block on `/etc/nginx/nginx.conf`\n\n```\nserver_tokens off;\nadd_header X-Frame-Options deny always;\nadd_header X-Content-Type-Options nosniff always;\nadd_header X-XSS-Protection \"1; mode=block\" always;\nadd_header Strict-Transport-Security \"max-age=31536000; includeSubDomains\" always;\nadd_header Cache-Control no-cache always;\nadd_header Referrer-Policy no-referrer always;\nadd_header X-Download-Options: noopen always;\nmore_clear_headers Server;\n```\n\n##### Turn off loging\n\nOn http block on `/etc/nginx/nginx.conf`:\n\n```\n# access_log  /var/log/nginx/access.log  main;\naccess_log off;\n```\n\nThen, outside the http block:\n\n```\nerror_log /home/ubuntu/www/error.log;\nerror_log off;\n```\n\n##### Worker connections\n\nOn `/etc/nginx/nginx.conf`\n\n```\nevents {\n  worker_connections  1024;\n}\n```\n\n##### Upstreams\n\nOn http block of `/etc/nginx/nginx.conf`, each server should point to a running instance of the app.\n\n```\nupstream mynodejsapp {\n  server localhost:3000;\n  server localhost:3001;\n  server localhost:3002;\n  server localhost:3003;\n}\n```\n\n##### geoip2 (optional)\n\nUse cases:\n- Country whitelisting.\n- Track user location.\n\n1. Set up [ngx_http_geoip2_module](https://github.com/leev/ngx_http_geoip2_module).\n2. Download and install\n\nAdd the following codes to `/etc/nginx/nginx.conf`:\n\nGet data from City database\n\n```\ngeoip2 /etc/GeoLite2-City.mmdb {\n  $geoip2_data_city_name   city names en;\n  $geoip2_data_postal_code postal code;\n  $geoip2_data_latitude    location latitude;\n  $geoip2_data_longitude   location longitude;\n  $geoip2_data_state_name  subdivisions 0 names en;\n  $geoip2_data_state_code  subdivisions 0 iso_code;\n}\n```\n\nGet data from Country database.\n\n```\ngeoip2 /etc/GeoLite2-Country.mmdb {\n  $geoip2_data_country_iso_code country iso_code;\n  $geoip2_data_country_name country names en;\n}\n```\n\nUse `$allowed_country` to find out if the country is whitelisted.\n\n```\nmap $geoip2_data_country_iso_code $allowed_country {\n  default no;\n  PH yes;\n}\n```\n\nThen on the `/etc/nginx/conf.d/default.conf`, inside the server block, respond with 403 when country is not whitelisted.\n\n```\nif ($allowed_country = no) {\n  return 403 \"Country not allowed\";\n}\n```\n\n##### headers-more\n\nSet up [headers-more-nginx-module](https://github.com/openresty/headers-more-nginx-module).\n\n##### Headers to forward\n\n```\nproxy_set_header Host $http_host;\nproxy_set_header X-Real-IP $remote_addr;\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\nproxy_set_header X-City-Name $geoip2_data_city_name;\nproxy_set_header X-Postal-Code $geoip2_data_postal_code;\nproxy_set_header X-Latitude $geoip2_data_latitude;\nproxy_set_header X-Longitude $geoip2_data_longitude;\nproxy_set_header X-State-Name $geoip2_data_state_name;\nproxy_set_header X-State-Code $geoip2_data_state_code;\nproxy_set_header X-Country-Iso-Code $geoip2_data_country_iso_code;\nproxy_set_header X-Country-Name $geoip2_data_country_name;\n```\n\n##### Forwarding www to non-www\n\nOn `/etc/nginx/conf.d/default.conf`\n\n```\nserver {\n  server_name www.mynodejsapp.ph; ## your domain here\n  return 301 $scheme://mynodejsapp.ph$request_uri;\n}\n```\n\n##### Handling file uploads\n\nOn the main server block on `/etc/nginx/conf.d/default.conf`\n\n```\nclient_max_body_size 0;\nproxy_send_timeout 180s;\nproxy_read_timeout 180s;\n```\n\n##### Serving locations\n\nOn the main server block on `/etc/nginx/conf.d/default.conf`\n\n```\nlocation / {\n  try_files $uri /index.html;\n}\n\n# Only if you are using the websocket\nlocation /socket {\n  proxy_http_version 1.1;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  # this is referring to upstream mynodejsapp\n  proxy_pass \"http://mynodejsapp\";\n}\n\nlocation /api {\n  # this is referring to upstream mynodejsapp\n  proxy_pass \"http://mynodejsapp\";\n}\n```\n\n#### Add SSL with LetsEncrypt\n\n1. `sudo add-apt-repository ppa:certbot/certbot`\n2. `sudo apt-get update`\n3. `sudo apt-get install python-certbot-nginx`\n4. `sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com`\n\nOnly valid for 90 days, test the renewal process with `certbot renew --dry-run`.\n\n#### NodeJS\n\n1. Install [nvm](https://github.com/nvm-sh/nvm)\n2. `nvm install node 13.x`\n3. `npm i -g db-migrate db-migrate-mysql`\n\n`db-migrate` and `db-migrate-mysql` modules are being used for database migrations.\n\n#### MySQL 8.0 (optional, you can use hosted solutions)\n\n[Source](https://www.tecmint.com/install-mysql-8-in-ubuntu/)\n\n1. `cd ~/Downloads`\n2. `wget -c https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb `\n3. `sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb`\n4. `sudo apt-get update`\n5. `sudo apt-get install mysql-server`\n6. `mysql --version`\n7. `sudo systemctl status mysql`\n\nIt's important to update the `.env` file for `db_host`, `db_user`, `db_pass`, `db_name`.\n\n#### Redis (only if using websocket but you can use hosted solutions)\n\n[Source](https://redis.io/topics/quickstart)\n\n1. `cd ~/Downloads`\n2. `wget http://download.redis.io/redis-stable.tar.gz`\n3. `tar xvzf redis-stable.tar.gz`\n4. `cd redis-stable`\n5. `make`\n6. `make test` (optional but recommended, will take some time to complete)\n7. `sudo make install`\n\nFollow the [start in the background guide](https://redis.io/topics/quickstart#installing-redis-more-properly)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faprilmintacpineda%2Fnodejs-express-jwt-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faprilmintacpineda%2Fnodejs-express-jwt-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faprilmintacpineda%2Fnodejs-express-jwt-boilerplate/lists"}