the actual mysql package appears to have a syntax error when used with node.js

So i’m trying to use mysql with nodejs, and when I attempt to use it, I receive a syntax error that appears to originate within the MySQL package itself.


which returns the exception:


SyntaxError: Invalid or unexpected token

Does anyone know why this might be happening?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

  1. init project:
npm init
  1. install mysql package:
npm i --save mysql
  1. connect to db (manual) :
const mysql = require('mysql');
const db = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '',
  database : 'databasenamehere'
db.query('SELECT * FROM test_table', (error, rows, fields) => {

Method 2

Thanks for the comments, guys. The solution was that I just had to install the latest version of the MySQL module from Github.

npm install mysqljs/mysql

forgot to add: I changed require(‘/usr/local/bin/mysql’) back to require(‘mysql’) after installing the latest version of MySQL as well.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x