Backend for the Grazing Earth mobile app.
.
├── ...
├── src
| └── auth # JWT middleware
| └── controllers # dispatch input; output
| └── db # PostgreSQL database definitions
| └── config # define database modes
| └── migrations # Sequelize migrations
| └── models # defines structure of PostgreSQL tables
| └── seeders # code to populate database with initial data
| └── errors # internal error handling
| └── routers # route url endpoint
| └── __tests__ # test cases for routers
| └── services # handles database queries and related functionality
| └── __tests__ # test cases for services
| └── validation # validates input w/ joi
| └── constants.ts # server constants
| └── server.ts # starting point of server
└── ...
- clone repo and
npm install
- Install PostgreSQL + management tool
- Make sure to do
npm install --save-dev sequelize-cli
if you don't have the sequelize cli yet. - Windows
- Install Windows Subsystem for Linux (WSL)
- Follow directions here to install PostgreSQL on WSL
- Install pgAdmin
- Follow directions here to connect pgAdmin to PostgreSQL and WSL
- MacOS
- Create a PostgreSQL DB called
grazing_earth
if setting up locally, using your GUI of choice (Postico or pgAdmin). - Create a
.env
file in the root directory
- Should be in the following format:
-
AUTH_SECRET=*secret assortment of characters used for encryption* PORT=4000 DATABASE_URL=postgres://username:password@localhost:5432/grazing_earth AWS_ACCESS_KEY_ID=*see credentials doc* AWS_SECRET_ACCESS_KEY=*see credentials doc* S3_BUCKET_NAME=*see credentials doc* SENDGRID_EMAIL=*see credentials doc* SENDGRID_API_KEY=*see credentials doc* DEBUG=true
- Run
npx sequelize db:migrate
to apply migrations to DB. - Run
npx sequelize db:seed:all
to load initial data. - App should be ready for use now
npm start
to run in production modenpm run dev
to run with hot reloading
Download the Redux DevTools extension.
ESLint is set up in this project. To keep code clean, always remember to run npm run lint
and fix any lint problems before merging into master.
Jest unit testing is set up for the controllers, routers, and services. Remember to run npm test
and fix any breaking changes that might've occured.
- You can also run just an individual test file with
npm test -- *filename*
- Eric Lu '25