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

198
Views
How to run a psql create table script from nodejs code

I want to know what is the convention to do this instead of doing this directly from the terminal. I have done research but no one asked the same question. For me, I actually have a external sql file.

Here is my songs.sql file

CREATE DATABASE songify;

CREATE TABLE songs (
  song_id BIGSERIAL PRIMARY NOT NULL,
  song_name VARCHAR(100) NOT NULL,
  artist VARCHAR(50) NOT NULL,
  albulm VARCHAR(100) NOT NULL,
  year_of_release SMALLINT,
  featured_artists VARCHAR(150)
);

Here is my db.js file

const Pool = require('pool').Pool;

const db = new Pool({
  user: 'postgres',
  password: 'Basketball1',
  host: 'localhost',
  database: 'songify'
});

module.exports = db;

Here is the index.js file which I think is supposed to run the create table script from the songs.sql file

const express = require('express');
const cors = require('cors');
const app = express();
const db = require('./db');

app.use(cors());
app.use(express.json());

app.get('/', (req,res) => {
  res.status(200).json('hello world');
});

const PORT = 5000;

app.listen(PORT, () => {
  console.log(`app listening on port ${PORT}`);
});

Please let me know if my assumption about how to do this is correct or if there is a convention that I am supposed to follow. Thanks!

about 4 years ago · Juan Pablo Isaza
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!