PostgreSQL
Implementation:
Step 1: Setup a server site application
Prerequisites
Install required packages
Node JS Express (express)
PostgreSQL (pg)
Cross-Origin Resource Sharing (cors)
Body Parser middleware (body-parser)
npm install express pg cors body-parserSetup server using Express (server.js)
const express = require('express');
const { Client } = require('pg');
const cors = require('cors');
const bodyParser = require('body-parser');
const app = express();
app.use(cors());
app.use(bodyParser.json());
const port = 5000;
const client = new Client({
user: 'postgres', // username of postgreSQL database
host: 'localhost', // host of postgreSQL database
database: '', // name of the database
password: '', // password of your postgreSQL application
port: 5432, // default port 5432
});
client.connect();
//method to interact with the database
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});Set up method (interact with database)
Run the express server
In terminal
Step 2: Setup a client site application
Prerequisites
Install required packages
Axios Vue 3 (axios)
Example: Retrieve data and display on screen
frontend code to display received data
method to retrieve data using axios
Run the client site application
Last updated