This is the backend of the PERN Stack application. It is built using Express and provides the API endpoints for fetching word types, words, and submitting sentences.
- Clone the repository.
git clone ...
- Navigate to the
backend
directory.cd backend
- Run the following command to install the dependencies:
npm install
- Update the database connection configuration in the
.env
file.
PORT = <serverPort eg.5000>
POSTGRES_HOST = <dependingOnEnvironment eg.localhost>
POSTGRES_USER = <postgresUsername>
POSTGRES_PASSWORD = <postgresUserPassword>
POSTGRES_PORT = <standardDBPort = 5432>
POSTGRES_DB = <postgresDatabaseName>
- Start the backend server with the following command:
npm run dev
ornpm start
- The server will run on http://localhost:5000.
GET /api/v1/wordtypes
: Retrieves the list of word types.GET /api/v1/${selectedType}
: Retrieves words of a specific type.GET /api/v1/sentences
: Retrieves all previously submitted sentences.POST /api/v1/sentences
: Submits a new sentence.
- Express
- Cors
- pg (PostgreSQL client)
- dotenv (for environment variables)
This is the PostgreSQL database used for storing word types, words, and submitted sentences.
- Install PostgreSQL on your system if not already installed.
- Create a new database for the application.
- Update the database connection configuration in the
.env
file of the backend. - In my case, I have used the official postgres docker image to run in a container
docker run --name <nameOfTheContainer> -e POSTGRES_PASSWORD=<databaseUserPassword> -p 5432:5432 -d postgres`
- To stop the container:
docker stop <nameOfTheContainer>
- To start the container:
docker start <nameOfTheContainer>
The database schema consists of the following tables:
see the database.sql
file
You can use the following SQL statements to insert sample data into the tables:
see the database.sql
file
- Implement Express Router, server.js file is becoming bloated
- Add PUT, DELETE sentences routes to complete CRUD operations