{"id":19146601,"url":"https://github.com/theroughcode/road-to-node-htn-2019","last_synced_at":"2026-05-16T22:07:37.131Z","repository":{"id":38803187,"uuid":"207031571","full_name":"theRoughCode/Road-To-Node-HTN-2019","owner":"theRoughCode","description":":pizza: Sample repo for a web server.","archived":false,"fork":false,"pushed_at":"2023-01-09T11:54:26.000Z","size":152,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T22:35:57.421Z","etag":null,"topics":["hackathon","hackthenorth","nodejs","webserver"],"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/theRoughCode.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}},"created_at":"2019-09-07T22:14:07.000Z","updated_at":"2019-09-14T03:33:41.000Z","dependencies_parsed_at":"2022-09-12T01:51:18.781Z","dependency_job_id":null,"html_url":"https://github.com/theRoughCode/Road-To-Node-HTN-2019","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/theRoughCode%2FRoad-To-Node-HTN-2019","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRoughCode%2FRoad-To-Node-HTN-2019/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRoughCode%2FRoad-To-Node-HTN-2019/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theRoughCode%2FRoad-To-Node-HTN-2019/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theRoughCode","download_url":"https://codeload.github.com/theRoughCode/Road-To-Node-HTN-2019/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240229974,"owners_count":19768597,"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":["hackathon","hackthenorth","nodejs","webserver"],"created_at":"2024-11-09T07:47:26.527Z","updated_at":"2026-05-16T22:07:37.101Z","avatar_url":"https://github.com/theRoughCode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Road to Node - Hack the North 2019 \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Node.js_logo.svg/2000px-Node.js_logo.svg.png\" width=\"100px\"\u003e\n\nWelcome to Road to Node!  In this workshop, we'll be going through a basic example of a web server complete with database interaction.  The goals of this workshop are:\n- Introduce Node.js and express to setup a local server\n- Introduce routing\n- Introduce HTTP requests (POST, GET, DELETE) with Postman\n- Integrate with Firebase API\n\nYou can check out the slides [HERE](https://docs.google.com/presentation/d/1Gufz0Yj0IhMx1XAN_nYnROz7aKQpFEUgS9qzlq-ATf0/edit?usp=sharing)!!\n\n## What You Need to Have\nFirst, make sure you have the following installed:\n1. **Install Node.js** [here](https://nodejs.org/en/)\n    - To check if you have it installed:\n      1. Open CLI (Command Line Interface)\n        - Windows:\n          - Open the **Run** window (Win + R)\n          - Type \"cmd\"\n        - Mac:\n          - Open **Applications** -\u003e **Utilities** -\u003e **Terminal**\n      2. Type ```node -v``` and hit **Enter**\n      3. If successful, you should get the version number (i.e. ```v8.11.0```)\n2. Text Editor (If you already have a preferred Text Editor, ignore the following subpoints)\n    - [Atom.io](https://atom.io/)\n    - Install helpful packages:\n      - [autoclose-html](https://atom.io/packages/autoclose-html) - autocloses HTML tags\n      - [javascript-snippets](https://atom.io/packages/javascript-snippets) - shortcuts for JS functions\n    - [HOW DO I INSTALL ATOM PACKAGES???](http://flight-manual.atom.io/using-atom/sections/atom-packages/)\n3. [Google Chrome](https://www.google.ca/chrome/browser/desktop/index.html)\n4. Install nodemon: ```npm install -g nodemon```\n5. Install Postman [here](https://www.getpostman.com/downloads/)\n6. Clone this repo.\n7. Go into this folder and run `npm install` or `npm i` to install dependencies\n\n## Project Structure\nBefore we dive into the code, here's an overview of how this project is organized.  The structure might seem a bit overkill for such a small example, but this structure is designed to be scalable for larger projects.\n\nIn the root folder, we have:\n- `app.js`: This is our entry file for our server.  In this file, we set up the necessary configs for our server and start the server with `app.listen()`.\n- `index.html`: This is our front end which displays our list of users.\n- `package.json`:  Our configuration for our build and makes it easily reproducible.  It contains a list of our packages that any one who downloads our package can install with `npm install`.  The `main` attribute determines the entry point for your app (i.e. `app.js`).\n- `package-lock.json`: Automatically generated file when you run `npm install` and modify the package dependency tree.  You won't need to touch this file.\n- `.gitignore`: Contains files that you don't want git to push to your online repo.\n\nThe `routes` folder contains our endpoints for our server:\n- `index.js`: Entry point for our routes.  It is a directory for different routes.  We currently only have one sub-directory for `users`.  You can extend this file by adding more subdirectories like `customers` or `merchandise`.\n- `users.js`: Contains all endpoints that live under the `users` subdirectory.  This is the file you'll be working with to implement required endpoints.\n- `solutions.js`: Solutions for `users.js`.\n\nThe `db` folder has functions that serve as the interface to our database:\n- `index.js`: Imports Firebase API and exports references to the directories in the database.\n- `users.js`: Holds all `users` database functions.\n\n## Setting up `UsersRouter`\nNow that you have an idea of the general project structure, let's look into implementing `UsersRouter`.  We first begin by creating `UsersRouter` and importing the required database functions:\n```javascript\nconst UsersRouter = require('express').Router();\nconst usersDB = require('../db/users');\n```\nWe use a `Router` to keep our routing clean and structured.  Next, we can begin defining our endpoints. The general format of defining an endpoint with Express.js is: `UsersRouter.\u003cHTTP Request Method\u003e('\u003cendpoint\u003e', reqHandler)`, where `reqHandler` is a function that takes in a request as its first argument and a response as its second.  An example of a default endpoint has been given to you:\n```javascript\nUsersRouter.get('/', (req, res) =\u003e res.send('Welcome to Road to Node!'));\n```\nNow, it's your turn to give it a try at implementing the example endpoints given to you in that file!  You can refer to the [Express.js API docs](https://expressjs.com/en/5x/api.html#req) for help.  Any database functions you'll need are all in `db/users.js`, or if you're really stuck, you can find the solutiosn in `routes/solutions.js`.\n\n## Running your server\nTo run your server, go into your terminal and run `nodemon` or `node app.js`.  You can use Postman to test your endpoints to see if they work.  Download the endpoints [here](https://tinyurl.com/yym6x9bk).  You can also open `index.html` to see your users list being populated!\n\u003cbr /\u003e\n\u003cbr /\u003e\n![image](https://user-images.githubusercontent.com/19257435/64902885-bf490300-d67d-11e9-96d2-4cea9fd7891f.png)\n\u003cbr /\u003e\n\n## Hosting your server\nYou can host your server on [Heroku](heroku.com) which has a free tier that I like to use. To set it up:\n1. Create Heroku account\n2. Create Procfile with the following content: `web: node app.js`\n3. Run:\n```\nheroku create\ngit push heroku master\nheroku ps:scale web=1\nheroku open\n```\nFor more details, check out [this tutorial](https://devcenter.heroku.com/articles/getting-started-with-nodejs).\n\n\n## Useful Resources\n- [Firebase set-up guide](https://firebase.google.com/docs/admin/setup)\n- [Express.js API docs](https://expressjs.com/en/5x/api.html#req)\n- [Heroku Node.js tutorial](https://devcenter.heroku.com/articles/getting-started-with-nodejs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheroughcode%2Froad-to-node-htn-2019","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheroughcode%2Froad-to-node-htn-2019","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheroughcode%2Froad-to-node-htn-2019/lists"}