DEV Community

Margaret W.N
Margaret W.N

Posted on

Day 44: TypeOrm and Heroku bug fixes.

Heroku bug fixes

I finally fixed the error encountered on deploying backend to heroku. I changed the main in package json from index.js (which is none existent in my project) to app.js which is my program's entry point and everything was working in no time.

 "main": "app.js",
Enter fullscreen mode Exit fullscreen mode

I also added my .env variables to heroku. The backend is up and running and almost ready to be consumed.
Response from app on browser:
Image: response on browser

Typeorm

Onto the next business of the day, learning typeORM. My key takeaways:

  • TypeORM supports both Active Record and Data Mapper patterns. Active record pattern encompasses accessing the database from the models while Data Mapper pattern uses repositories to access the database instead of models.
  • Data mapper pattern is preferred in large systems because it easily maintainable while Active Records are preferred cause of their simplicity.
  • We use either a repository or entity manager to save data to our database. Each entity has a repository.
  • Creating a model:
import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";

@Entity()
export class User {

    @PrimaryGeneratedColumn() //generated id
    id: number;

    @Column()//column
    firtName: string;

    @Column()
    lastName: string;

    @Column()
    email: string;
}
Enter fullscreen mode Exit fullscreen mode
  • @expression is a typescript decorator.

That's it for today, looking forward to diving deeper into typeORM.
Day 44

Top comments (0)