node-postgres create database

后端 未结 4 1818
孤城傲影
孤城傲影 2021-01-03 20:45

I am using node-postgres, and at the beginning of my application I want to check whether the database exists or not. So my workflow idea is as following:

  1. Check
4条回答
  •  感情败类
    2021-01-03 20:56

    I've just written a module for that: https://github.com/olalonde/pgtools

    var pgtools = require('pgtools');
    pgtools.createdb({
      user: 'postgres',
      password: 'some pass',
      port: 5432,
      host: 'localhost'
    }, 'test-db', function (err, res) {
      if (err) {
        console.error(err);
        process.exit(-1);
      }
      console.log(res);
    });
    

    Hopefully it can make your code a bit cleaner.

提交回复
热议问题