https://backend-assessment-2023-q3-private.onrender.com/
- Fork this repo.
- Clone your fork to your computer.
- Install dependencies:
npm install
- Start the server:
npm start
In this challenge, you will use the Express API in this repo, which serves hard-coded data from a JSON file, and:
- deploy this API to render
- create a database for the API on ElephantSQL
- create a
users
table in your database - seed the table with the data from
usersData.json
- refactor the controllers and queries to serve data from your db
- deploy your changes so that your API on render calls the db
See the Detailed instructions section below for detailed instructions, tips, and hints.
You can use the resources listed below to help you.
If you use code from any other resource (Stack Overflow, your own project, etc.) you must put the link to that source in a comment.
- Deploy your API to render.
- Make sure that all routes work.
- Paste your deployed URL in the top of this README.
- Commit and merge your changes to the main branch of your fork.
- Create a database on Elephant SQL
- Do not commit the connection string / URL to GitHub
- Create a
schema.sql
file in this repo that defines the table. The columns should match the keys and data types you see in theusersData.json
file. - Run the schema file to create the table in your db.
- Commit and merge your changes to the main branch of your fork.
You can use
float
as the data type forlatitude
andlongitude
.
- Create a
seeds.sql
file in this repo that adds at least 3 students fromusersData.json
to theusers
table. - Commit and merge your changes to the main branch of your fork.
Don't waste time copy-pasting every single user from the JSON file. Just do 3 to start. Do the rest if you have time at the end.
The
about
texts have apostrophes. (For example:'Hi there! I'm Park...'
). These will cause problems because SQL statments require single quotes around strings.You can escape a single quote in a SQL statement by repeating it:
'Hi there! I''m Park...'
- Refactor the queries and controllers to fetch from the database.
- You will need to use
pg-promise
. It is already installed. - Use environment variables to store the connection string (database URL).
- Delete the
usersData.json
file. - Commit and merge your changes to the main branch of your fork.
- If it works locally, update your environment variables on Render, then push, merge, and deploy your code changes.
- By the end of this step, your deployed database should serve data from the db.
- As you write code, commit it and merge it to the main branch of your fork (not the upstream repo)
- When the instructions say to commit and merge code, commit and merge to your fork (not the upstream repo)
- There should be at least one commit for each of steps 1-6 above, with clearly written commit messages.
- At the end of class, make a PR of your main branch to the upstream repo main branch (so I can review your code)
After each step of the challenge, before you commit your code, make sure that all of these routes function as expected.
/
: returns a200
response: `{ data: 'Service is running' }/users
: returns a200
response in this format:{ data: [ {//user 1...}, { // user 2, ...}, ...]}
/users/:id
: returns a200
response in this format:{ data: { name: ..., age: ..., }}
/users/:id
: returns a404
response if the id does not exist:{ error: 'User with id ... not found'}
Deploying the API to render
Creating the DB and connecting API to DB
Create and seed data; serve data from DB
Reference code
Deployed example of completed assessment https://backend-assessment-2023-q3-private.onrender.com/