我想创建一个REST API来实现在我的postgres数据库中执行的CRUD函数。我使用node.js进行了此操作,并遵循了下一页上的说明:http://mherman.org/blog/2016/03/13/designing-a-restful-api-with-node-and-postgres/
实现第一个GET请求的业务逻辑后,我想通过在Web浏览器中调用url进行测试。我的浏览器中生成了一个错误:
error: Password authentication failed for user Felix
at Connection.parseE (C:\Users\Felix\node-postgres-promises\node_modules\pg\lib\connection.js:539:11)
at Connection.parseMessage (C:\Users\Felix\node-postgres-promises\node_modules\pg\lib\connection.js:366:17)
at Socket.<anonymous> (C:\Users\Felix\node-postgres-promises\node_modules\pg\lib\connection.js:105:22)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)
我想知道的是,“ Felix”是我的Windows用户的名称,而不是postgres用户名。所以我想我的系统尝试使用Windows用户凭据连接到postgres。因此,我的问题是现在可以在哪里配置API使用的设置。 npm-cache / _logs中的日志文件显示以下消息:
1 verbose cli 'start' ]
2 info using npm@5.6.0
3 info using node@v8.11.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle node-postgres-promises@0.0.0~prestart: node-postgres-promises@0.0.0
6 info lifecycle node-postgres-promises@0.0.0~start: node-postgres-promises@0.0.0
7 verbose lifecycle node-postgres-promises@0.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle node-postgres-promises@0.0.0~start: PATH: //my path stuff
9 verbose lifecycle node-postgres-promises@0.0.0~start: CWD: C:\Users\Felix\node-postgres-promises
10 silly lifecycle node-postgres-promises@0.0.0~start: Args: [ '/d /s /c', 'node ./bin/www' ]
11 silly lifecycle node-postgres-promises@0.0.0~start: Returned: code: 1 signal: null
12 info lifecycle node-postgres-promises@0.0.0~start: Failed to exec start script
13 verbose stack Error: node-postgres-promises@0.0.0 start: `node ./bin/www`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at EventEmitter.emit (events.js:214:7)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at ChildProcess.emit (events.js:214:7)
13 verbose stack at maybeClose (internal/child_process.js:925:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid node-postgres-promises@0.0.0
15 verbose cwd C:\Users\Felix\node-postgres-promises
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v8.11.3
19 verbose npm v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error node-postgres-promises@0.0.0 start: `node ./bin/www`
22 error Exit status 1
23 error Failed at the node-postgres-promises@0.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]