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

196
Visualizações
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
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