USING POSTMAN TO TEST THE APIS
Run the server type
npm init
node api.js
nodemon api
1. Install packages:
npm install pg --save
npm install express --save
npm install body-parser --save
npm install nodemon --save
2. Create Database Connection:
Create a file called connection.js
This file would hold the connection data as shown below:
const { Client } = require("pg");
const client = new Client({
host: "localhost",
user: "postgres",
port: 5432,
password: "sa",
database: "postgres",
});
module.exports = client;
3. Create the Server and Client
Node.js allows us to create a server. Now we need to create a second file.
Here I call it api.js
Write the following code inside. This code creates a server listening at port 3300. Then a client is create as well that connects to the server.
const client = require("