This script can be used to check connection to a database and receive data from it.
- Create a
.envfile, containig the database credentials npm installnode dbcon.js
These are examples of how the created functions can be used to read and write from and to the database.
Reading data from database:
const data = await getUsers();
console.log("users :>> ", data);Writing/inserting data to database:
// Example of creating a new user
const newUser = await createUser(
"john.doe@domain",
"John",
"Doe",
"HASH",
"Employee",
"Active",
"Networks"
);
console.log(newUser); // see changes such as id createdThis can be the potential structure.
node/
|-- db/
| |-- dbcon.js
| |-- user.js
| |-- # other files like user.js for specific tables
|-- routes/
| |-- # (express?) routes to use the database files