C
C
Chikibombaster2022-03-05 18:55:50
MySQL
Chikibombaster, 2022-03-05 18:55:50

How to connect MySQL in Node.JS?

Can't connect Mysql to JS. I have already tried a bunch of different options, then "Uncaught ReferenceError: require is not defined" , then "Uncaught SyntaxError: Cannot use import statement outside a module"
Did this:
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const mysql = require("mysql2");

And so:
const mysql = require("mysql");
And so:
const mysql = require("mysql2");

It's an error all the time, but I can't find how to fix it on the Internet.
Inserted "type": "module" into package.json, does not help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2022-03-05
@rPman

and npm install mysqldid?
dock

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question