Currently, I am utilizing Express, Postgres, and TypeORM for a small-scale website development project.
However, I am encountering challenges when it comes to establishing a connection between TypeORM and my Postgres database.
index.ts
( async ()=>{
console.log("before") <-- This message appears
await createConnection()
console.log("after") <-- Unfortunately, this message does NOT appear
app.listen(4000, ()=>{
console.log('express server is listening on port 4000')
})
})()
ormconfig.json
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "postgres",
"database": "jwtauthexample",
"synchronize": true,
"logging": true,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}
To establish my postgres database and user credentials, I followed these steps:
brew install postgres
psql postgres
in the terminalCREATE DATABASE jwtauthexample
CREATE USER postgres WITH ENCRYPTED PASSWORD postgres
GRANT ALL PRIVILEGES ON DATABASE jwtauthexample TO postgres
Despite following all these procedures, I am uncertain about where I might be going wrong.
Notably, the same index.ts
code worked seamlessly a few weeks back. However, after deleting postgres, the connection cannot be established using the same process that was previously effective.
I strongly suspect that the issue lies with await createConnection()
, as the line console.log("before)
fails to execute whenever I run:
yarn start
(through nodemon)