Tag: 节点postgres

当使用asynchronous等待,如何指定一个callback?

我正在研究如何在以下方面使用交易: https://node-postgres.com/features/transactions 但在下面的代码示例中: const { Pool } = require('pg') const pool = new Pool() (async () => { // note: we don't try/catch this because if connecting throws an exception // we don't need to dispose of the client (it will be undefined) const client = await pool.connect() try { await client.query('BEGIN') const { rows […]

Node.js / Express – 如何获取在path/ index.js app.js中定义的variables?

我是Node.js和Express的新手。 我如何访问“routes / index.js”中名为“pg”的“app.js”中创build的variables? app.js /** * Module dependencies. */ var express = require('express'); var routes = require('./routes'); var user = require('./routes/user'); var http = require('http'); var path = require('path'); var pg = require('pg'); var conString = "postgres://someuser:somepass@localhost/postgres" var app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); […]