{"id":16702332,"url":"https://github.com/jagcesar/node-api","last_synced_at":"2025-03-14T06:44:11.044Z","repository":{"id":145181497,"uuid":"48559015","full_name":"JagCesar/node-api","owner":"JagCesar","description":null,"archived":false,"fork":false,"pushed_at":"2016-04-10T17:58:12.000Z","size":24,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T01:31:20.926Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/JagCesar.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":"2015-12-24T23:08:52.000Z","updated_at":"2016-01-13T21:17:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"e322102c-2a87-4107-b239-b682307b49c6","html_url":"https://github.com/JagCesar/node-api","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/JagCesar%2Fnode-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JagCesar%2Fnode-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JagCesar%2Fnode-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JagCesar%2Fnode-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JagCesar","download_url":"https://codeload.github.com/JagCesar/node-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243538116,"owners_count":20307101,"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":[],"created_at":"2024-10-12T18:47:35.132Z","updated_at":"2025-03-14T06:44:11.033Z","avatar_url":"https://github.com/JagCesar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Learning [Node.js](https://nodejs.org), [koa](http://koajs.com), [JWT](http://jwt.io), [Postgres](http://www.postgresql.org), [Postgis](http://postgis.net) and [Heroku](https://www.heroku.com)\n\nI needed to create an API for a side project so I decided to learn how it could be done. My JS skills are terrible, and this is the first time I play around with Postgres and Heroku. So if you find any errors, please post a Pull Request :)\n\n# Features\n\n- JSON responses\n- Validation of arguments\n- User registration, returns a unique JWT if successful\n- Protected endpoints that require the user to send a valid JWT to gain access\n\n# Prerequisites\n\nTo get this up and running you have to set up a Heroku web dyno and a Heroku Postgres database. [They have a great tutorial for this if you're unsure how to do this](https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction).\n\n# Location, location, location\n\nTo store locations in our database we use [Postgis](http://postgis.net), which is available on Heroku.\n\nWhen saving a coordinate in the database we want to store lon, lat and SRID. SRID is a unique identifier that defines which coordinate system the coordinates are defined in. We store the SRID to be able to mix different different type of coordinates in the future. Coordinates sent to us from iOS are using SRID `4326`. Google maps uses the same SRID. [I found this information here](http://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet).\n\n# Environment vars\n\nSome variables aren't available in the code, such as `process.env.DATABASE_URL`, `process.env.PORT` and `process.env.JWT_SECRET`. I made this on purpose since these would give you access to my Heroku environment. To set these values you create a file named `.env` in your cloned repository folder and add this content:\n\n```\nDATABASE_URL='postgres://john:appleseed@example.com:5432/databaseName?ssl=true'\nHTTP_TIMEOUT=10000\nPORT=4000\nJWT_SECRET='shared-secret'\n```\n\nRemember to change the `JWT_SECRET` to a random string to verify that the JWTs you receive are signed by you.\n\nNext thing you have to do is install [node-foreman](https://github.com/strongloop/node-foreman). Do it by writing `npm install -g foreman` in your terminal.\n\n# Get it running 🏃\n\nMake sure you're in the cloned repository folder, then do the following:\n- Write `npm install` to install the dependencies needed\n- Write `npm start` to get the service up and running locally\n- Write `curl http://localhost:4000/db` to create the required tables in the database\n\n# Endpoints\n\n- `/` Writes out hello world. Nothing fancy\n- `/db` Creates the tables needed and sets up PostGIS\n- `/register` Creates a new user entry in the database with a unique uuid. Then signs a new JWT that contains this uuid and returns it.\n- `/refreshToken` Creates a JWT and returns is. Requires a `private_token` to be sent as a GET query.\n- `/locations` Lists all available locations. Requires a valid JWT.\n- `/locationsCloseToMe` Lists all locations close to the coordinates sent. Send `lat`(latitude) and `lon`(longitude). Requires a valid JWT. The JWT has to be provided as a HTTP Header (`Authorization`).\n- `/checkIn` Creates a new entry in the the `check_ins` table in the database connected to the current user. This endpoint requires `locationGuid` to be sent as a GET query, and a valid JWT. The JWT has to be provided as a HTTP Header (`Authorization`). You'll find a location guid by listing locations.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjagcesar%2Fnode-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjagcesar%2Fnode-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjagcesar%2Fnode-api/lists"}