I am trying to create a database setup script for a nodeJS project.
I have the following async function createTable
that queries a PostgreSQL database.
The problem is that the script does not quit after all the operations have been carried out.
I have tried appending process.exit(0)
to the end of the file but that just prematurely kills the script (I think it executes while the async operations are running).
How do I properly exit the script after operations are done?
const dbInit = () => {
const createTable = async (creationQuery, tableName) => {
try {
const created = await client.query(creationQuery);
if (created) logger(`'${tableName}' table created successfully`);
} catch (err) {
logger(err.message);
}
};
createTable(Schemas.userModel, 'Users');
createTable(Schemas.orderModel, 'Orders');
};
dbInit();