Example of using pg-copy-streams to seed a postgres database with a file. (https://www.npmjs.com/package/pg-copy-streams)

dependencies used:

  • node, npm
  • psql cli
  • local postgres database (with database mydb as defined in package.json, and table mytable as defined in schema.sql)

how to use:

  • add your dbcreds.js file matching the sample.
  • npm run clear to clear the db.
  • npm run seed to seed the db.
  • npm start to start server.
  • visit localhost:3000 in browser to see the seeded db rows (or inspect the db through cli).

references:

other links: