Story points | 5 |
Tags | node sql |
Hard Prerequisites | |
IMPORTANT: Please review these prerequisites, they include important information that will help you with this content. | |
|
You are required to create a backend service that will help capture basic information about prospective students who come to inquire here at Umuzi.
Before you dive into anything too intense, let’s make sure that you can get node to connect to your database. Can you get this Node script to run:
// npm install --save pg
// find out more here: https://node-postgres.com/
const Pool = require("pg").Pool;
const pool = new Pool({
user: "user",
host: "localhost",
database: "db",
password: "pass",
port: 5432
});
const helloWorld = () => {
pool.query(
"SELECT $1::text as message",
["Hello world!"],
(error, results) => {
if (error) {
throw error;
}
console.log(results.rows);
}
);
};
helloWorld();
Create a single index script with the following functions:
addNewVisitor
. This should save the Visitor into the databaseYou will be expected to properly test your code. You can use whatever testing framework you want. If you use something that isn’t taught at Umuzi please justify your choice (if you found something cool we might incorporate it into the syllabus)
.dotenv
module has been utilized..dotenv
file should not be present in the repo and should be specifically excluded through the use of .gitignore.
docker-compose.yml
file should be at the root of the project.Pool.connect || Client.connect
and Pool.end || Client.end
is used correctly. There is generally no need for opening and closing your connection inside every function.return
, not console.log
.