我在一个小型网站上使用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数据库和用户,如下所示
brew install postgres
psql postgres
在我的终端上CREATE DATABASE jwtauthexample
CREATE USER postgres WITH ENCRYPTED PASSWORD postgres
GRANT ALL PRIVILEGES ON DATABASE jwtauthexample TO postgres
我不确定自己在做什么错。
index.ts
几周前,相同的代码正在工作。然后我删除了postgres,它无法再使用我一直使用的相同程序进行连接。
我很确定问题出在哪里,await createConnection()
因为console.log("before)
一旦我运行它就不会执行该行:yarn start
(with nodemon)
解决了
我忘了跑步:npm install pg --save
在我的应用内
如果使用纱线,请执行以下操作: yarn add pg
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句