Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question