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

453
Views
Node JS, MYSQL connection.query no es una función

db_config.js:

 const mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '', database: 'test' }) connection.connect(function(err){ if(!!err){ console.log(err) } else{ console.log('Connected') } }) module.export = connection

Usuarios.js

 var express = require('express'); var router = express.Router(); var connection = require('../db_config') /* GET users listing. */ router.get('/comments', function(req, res, next) { var getCommentsQ = "SELECT * FROM `comments`"; connection.query(getCommentsQ, function(err, result){ if(err){ console.log(err) res.send('Unable to get the comments') } else{ res.send(result) } }) }); module.exports = router;

Error: cada vez que voy a "localhost: 3000/users/comments" dice: "connection.query is not a function"

Seguí este tutorial: Estaba siguiendo este tutorial, el suyo funcionó, el mío no funciona

Advertencia de que usa Jade, estoy usando Ejs, pero creo que no es un problema del motor de visualización.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tiene un error tipográfico en su exportación, intente exportar su connection de esta manera.

 module.exports = connection;
about 4 years ago · Juan Pablo Isaza Report
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!