DEV Community

Margaret W.N
Margaret W.N

Posted on

2 2

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay