Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!