Node.js with TypeORM.
Hi Friends, In this article, I will explain about node js with TypeORM.
I will write node.js with TypeORM multiple parts.
PART 1
For part 1 I cover only initial setup. Before I explain about the initial setup. I will give a simple introduction to TypeORM.
What is TypeORM.
TypeORM is specifically an ORM that converts data between JavaScript / TypeScript to a variety of databases: MySQL / MariaDB / Postgres / SQLite / Microsoft SQL Server / Oracle / sql.js.
More detail about TypeORM
ORM is Object-relational mapping.
Initial setup.
Install globally
$ npm install typeorm -g
Create a project
$ typeorm init --name graphql-ts-server-boilerplate --database postgres
In your ormconfig.json file set your DB collection.
In the above picture, I edited the username, password, database. We should create a database in Postgres. Install Postgres in your device.
Update tsconfig.json file from this link.
Create tslint.json file and update from this link.
Install dev dependencies.
$ npm install --save-dev tslint tslint-config-prettier nodemon
Set nodemon in your package.json.
$ "start": "nodemon --exec ts-node src/index.ts"
Run npm start
$ npm start
If your DB connection established successfully, npm start successfully.
Then setup graphql-yoga.
$ npm install graphql-yoga
Once you installed successfully edit index.ts file.
Finally, run the code.
$ npm start
It will open http://localhost:4000/
Thank you for reading. Have a great day!
Here is code: