Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Using PSQL command in npm script

I have a basic React project with a PSQL database. I have a db.sql file which holds the SQL code to create and fill in a database. I want to have an npm script in the package.json file to run the following PSQL command: psql -U postgres -f ./server/db.sql. This command works fine if I run it from the terminal, but doesn't if I try to call it through an npm script.

package.json file:

"scripts": {
  ...
  "database": "psql -U postgres -f ./server/db.sql"
}

Error when running npm run database:

[Tue Jul 06 2021 18:56:09 GMT+0200 (Central European Summer Time)] ERROR Error: ENOENT: no such file or directory, open './config/app.yml'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at Object.readConfig (C:\PATH\node_modules\yaml-config\lib\yaml-config.js:57:25)
    at Object.<anonymous> (C:\PATH\node_modules\psql\lib\config.js:2:23)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18) {
  errno: -4058,
  syscall: 'open',
  code: 'ENOENT',
  path: './config/app.yml'
}
Usage: C:\Program Files\nodejs\node.exe C:\PATH\node_modules\psql\bin\psql.js [query] [database]

Examples:
  C:\Program Files\nodejs\node.exe C:\PATH\node_modules\psql\bin\psql.js -g prod -g dev "SELECT User FROM mysql.user"    Lists all users from groups prod and dev.
  C:\Program Files\nodejs\node.exe C:\PATH\node_modules\psql\bin\psql.js "SELECT VERSION()"                              Get MySQL version from all servers


Options:
  -g, --group  Server group to execute the query on
  -d, --diff   Diff-only: Display the rows that are on one server only

Not enough non-option arguments: got 0, need at least 1

Expected result, as when running the command in the terminal directly:

$ psql -U postgres -f ./server/db.sql
Password for user postgres: 
You are now connected to database "temp-db" as user "postgres".
CREATE TABLE
COPY 117
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda