Bear sightings are on the rise nationwide. Unfortunately, there's no centralized website to upload and access bear sightings. This is a big problem!
Using Node.js, create an API that allows users to submit bear sightings as they happen and query the database for recent sightings with certain filters.
Your API should conform to the following spec:
Example POST body:
{ bear_type: 'grizzly', notes: 'It was a big one!', zip_code: '90210', num_bears: 3 }
Return an array of sightings, include a unique ID with each. Supported query params, all optional
`start_date` (inclusive) (default: all time)
`end_date` (inclusive) (default: all time)
`bear_type` (default: all types)
`zip_code` (default: all zip codes)
`sort` (default: created timestamp, ascending. only supported value is `num_bears`)
Return a single sighting object queried by its ID
Submit the final project via this form: https://docs.google.com/forms/d/1OGUVmjmpRXSRFxH0SRoTPfZHwagi1lQEuCnaVSr261E Please include a package.json or equivalent, but omit the node_modules directory. The form sometimes rejects zip files when node_modules is included.
npm start
api/__tests__- Contains thetestsscriptsapi/resources/v1- Allv1resourcesapi/swagger-swagger.yamlfile for resource definitionsdb/config- Database configurations for Sequelize ORMdb/migrations- Database migrationsdb/models- ORM Modelslib/constants- Constant definitions reused throughout applicationlib/middleware- Registered middlewareapp/server.js- Application entry point start script
Within Postgres, all of the relevant information is stored in the bearsightings table.
{
"id": "2a9f5abb-509c-493b-9b84-54442b1b9bfb",
"start_date": "2018-08-06T18:58:23.573Z",
"end_date": "2018-08-06T18:58:23.573Z",
"bear_type": "black",
"notes": "Wow!",
"zipcode": "20723",
"num_bears": 7,
"updatedAt": "2018-08-06T18:58:23.574Z",
"createdAt": "2018-08-06T18:58:23.574Z"
}
- Platform dependencies must be installed. You will need Node and Postgres.
- Install Homebrew
brew install nodebrew install postgres
- Create Postgres DB
>$ psql template1
>template1=# CREATE DATABASE dave_api;
.envfile
- Ensure
.envfile is created and has proper parameters. DB credentials should go here
- Software dependencies must be install.
yarn install- installsnode_modules
- DB Migrate
npm run db:migrate- sets up tables in database via migrations
- Start the app.
npm start
The file .env contains all of the server-side environment variables
- Deploy. The application is only available for local development. This should be deployed to a hosted server.


