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

195
Vistas
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 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