TypeORM无法成功连接到我的Postgres

Magofoco

我在一个小型网站上使用Express,Postgres和TypeORM。

我在将TypeORM与Postgres连接时遇到问题。

索引

( async ()=>{
    console.log("before")  <-- This gets printed
    await createConnection()
    console.log("after") <-- This does NOT get printed
    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"
   }
}

我创建了一个postgres数据库和用户,如下所示

  1. brew install postgres
  2. psql postgres 在我的终端上
  3. CREATE DATABASE jwtauthexample
  4. CREATE USER postgres WITH ENCRYPTED PASSWORD postgres
  5. GRANT ALL PRIVILEGES ON DATABASE jwtauthexample TO postgres

我不确定自己在做什么错。

index.ts几周前,相同的代码正在工作。然后我删除了postgres,它无法再使用我一直使用的相同程序进行连接。

我很确定问题出在哪里,await createConnection()因为console.log("before)一旦我运行它就不会执行该行yarn start(with nodemon)

Magofoco

解决了

我忘了跑步:npm install pg --save在我的应用内

如果使用纱线,请执行以下操作: yarn add pg

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章