Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda