A comprehensive and fully functional PostgreSQL (PSQL) database implementation. This database has been rigorously tested with approximately 40 different tests to ensure its robustness and seamless communication with the backend.
- JavaScript
- Node.js
- PSQL
- Jest
-
Clone this repo to your local machine
- Use
git clone <repository-url>
to clone the repository to your local machine.
- Use
-
Run "npm install"
- Execute
npm install
to install project dependencies.
- Execute
-
Install pg, express, and dotenv using the terminal
- Run the following command in your terminal:
npm install pg express dotenv
- Run the following command in your terminal:
-
Install supertest and jest as development dependencies using the terminal
- Install
supertest
andjest
as development dependencies:npm install --save-dev supertest jest
- Install
-
Ensure your local PSQL server is running
- Make sure your local PostgreSQL server is running.
-
Add the HOST, USER, DATABASE, and PORT as environment variables in a .env file
- Create a
.env
file in the project root directory and add the following variables with your local server details:USER="username_here" HOST="hostname_here" DATABASE="dbname_here" PORT="44333"
- Create a
-
Add this file to your gitignore file
- Ensure to add
.env
to your.gitignore
file to prevent it from being tracked by Git.
- Ensure to add
-
In the connection.js file, change the pool constant to "const pool = new Pool(localConfig);"
- Update the
connection.js
file to use your local configuration. Change thepool
constant declaration to:const pool = new Pool(localConfig);
- Update the
-
Uncomment the entire code in listen.js
- Uncomment all the code in
listen.js
file to ensure it runs locally. This might involve removing comment delimiters (/* ... */
) or uncommenting individual lines as necessary.
- Uncomment all the code in
These steps ensure that all necessary configurations and dependencies are set up correctly for running your Node.js application locally with PostgreSQL and testing capabilities enabled.
-
Setup Database Instance on Local Server
- Initialize the database instance on your local server:
npm run set-dbs
- Initialize the database instance on your local server:
-
Seed the Database
- Populate the database with initial data:
npm run seed
- Populate the database with initial data:
-
Verify Local Database Setup
- Before proceeding, confirm that your local server includes databases named
nc_news_test
andnc_news
, and these databases contain tables with initial data.
- Before proceeding, confirm that your local server includes databases named
-
Run Tests
- Execute tests to verify functionality:
npm test
- Execute tests to verify functionality: