Create A Simple HTML Website With Postgres Databas
Create A Simple HTML Website With Postgres Databas
[Type the abstract of the document here. The abstract is typically a short
summary of the contents of the document. Type the abstract of the
document here.]
Create a simple HTML website with
Postgres Database
#webdev#beginners#html#postgres#bluewave
Get Ready, Future Web Developers! Let's create a simple HTML website
that connects to a Postgres Database. For this example, we will be using
JavaScript (Node JS, and Express JS) for it's middleware functionalities.
Whether you want to showcase your portfolio, run a blog or complete a due mini
project on web development, web development is a skill that's still in demand.
We'll dive in to the process of building a simple HTML website from scratch. We'll
explore how to integrate a Postgres database, using JavaScript as middleware to
handle API requests. To spice things up, we can also be using Bootstrap5 to design
the webpage! But that will be covered in a different blog.
Technologies Used:
HTML5
Postgres (Database)
Express JS (Backend)
Prerequisites
Make sure Postgres is downloaded and ready to use. Also, download Node JS for
installing npm packages like Express JS, Body Parser and Postgres APIs.
Download Postgres here
Download NodeJS here
Now, we can start uploading some dummy data to the table via INSERT
command
Once we are done, adding the dummy data, we can view the Student table
with the below command
SELECT * FROM student;
If you followed the steps till now, you would get the
below student table!
Let's start adding the custom div blocks as per our needs
...
students_list div block is for showing the list of students that have been
registered to the database. We will be using Express JS to fetch the
data from Postgres and showcase it in the block.
Let's start building the script.js file for connecting HTML and
PostgreSQL.
Let's now create an express application connection and also, define the
port at which the server will be listening to.
Now, we have to parse HTML requests sent from the app. In simple
words, it's a middleware used to recieve data from users, such as
forms or uploads
(Don't add the above line if you are not planning to take input from
users. We will be adding a registeration form in the next blog and
that's why we require body-parser)
Setup a Route handler for the root URL ('/'). So that, when a GET
request is made to the root URL, the server responds by sending the
"index.html" file located in same directory
node script.js
Ukadayi wabata concept yeweb development frontend and back end engineer.