PostgreSQL and REST API

Preconditions:

=> Download NodeJS from https://nodejs.org/en/download

=> Download and install PostgreSQL from https://www.postgresql.org/download/windows/

=> Good to have Postman installed as well from https://www.postman.com/downloads/

=> Be familiar with JavaScript from https://www.hemelix.com/scada-hmi/twincat-hmi/twincat-hmi-async-function/

 

Once we have installed the PostgreSQL then we can create and build REST API.

=> Fire Visual Studio Code and create a folder called RESTAPI

=> Open a terminal (Terminal | New Terminal) and run the following command

npm init -y 

=> Hit enter and it will create a JSON file called package.json file under the RESTAPI folder

=> Install express framework by executing the following command

npm i --save express

=> Install PostgreSQl connector by executing the following command

npm i pg

Now create the structure of the folder of your project as you need.

=> Create  file called server.js with the following content

const express = require("express");
const app= express();
const port = 3000;
app.get("/", (req, res) => {
    res.send("Hello World, so far so good!");
});
app.listen(port, () => console.log(`app listening on port ${port}`));

=>

References

See Also :