Skip to content

NestJs API with Postgres - uses Clarifai API endpoints and PlantId endpoints to identify images and return plant data. Deployed to Heroku.

Notifications You must be signed in to change notification settings

chelsea-angelena/heroku_deploy

Repository files navigation

Description

Basic NestJs/Postgres Api - deployed with Heroku

Returns plant identification information for images posted to the 'identify' endpoint in base64

Check out the Swagger documentation

(local: Swagger documentation)

Installation

npm install

Dependencies

  • @nestjs/mapped-types
  • @nestjs/passport
  • @nestjs/platform-express
  • @nestjs/swagger
  • @nestjs/typeorm
  • @types/multer
  • bcryptjs
  • body-parser
  • clarifai
  • clarifai-nodejs-grpc
  • class-transformer
  • class-validator
  • cookie-parser
  • passport
  • passport-jwt
  • passport-local
  • pg
  • reflect-metadata
  • rimraf
  • rxjs
  • swagger-ui-express
  • typeorm

Running the app with Docker

  • update POSTGRES_HOST to be 'db' in the .env file
  • make run-local

Deploying The Docker Image

  • docker tag registry.heroku.com//
  • docker push registry.heroku.com//
  • heroku container:push release
  • heroku container:release web release

ie:

  • docker tag clar-server-server registry.heroku.com/clar-server/web
  • docker push registry.heroku.com/clar-server/web

Running the app locally

npm run start:dev

Environment

  • Add a .env (set to local environment)
MODE=devleopment
POSTGRES_HOST=localhost
POSTGRES_DATABASE=<db_name>
POSTGRES_USER=<db_user>
POSTGRES_PORT=5432
POSTGRES_PASSWORD=<db_password>

Deploy To Heroku

These are the steps for deploying an app to heroku:

  • heroku login
  • heroku create
  • package.json: node engine:
"engines": {
    "node": "16.x.x",
    "yarn": '1.2.x
  },

  • add a Procfile (no file type appended )
web: npm run start:prod

change main.js:

const port = process.env.PORT || 5000;
await app.listen(port);
}

Heroku will set the port env variable to a random port, so you need to use process.env.port.

This variable does need to be explicitly set

Set Heroku env vars:

  • heroku config:set = --app

    heroku config:set NODE_ENV=development --app typescript dev dependencies will be needed at build time

    heroku config:set MODE=production --app since NODE_ENV = development, we want to set this to production to specifiy SSL true in our database module during production vs local development

    (Even though we are calling this production, this is a 'development deployment' as it is not really configured/scalable for production)

Commit changes, push to: git push heroku main

Adding Heroku Database

  • Log in to heroku -> addons -> search 'postgres'

  • select Heroku Postgres--> Hobby Free

  • open Resources tab --> click on the database name

  • copy down values for the database settings

  • In the terminal at the root dir of your project, add the values from your postgres heroku add on, name them exactly as you have set up in your .env file

    • heroku config:set = --app

License

MIT licensed.

About

NestJs API with Postgres - uses Clarifai API endpoints and PlantId endpoints to identify images and return plant data. Deployed to Heroku.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published