Canno't find mysql module - error

I installed nodejs and mysql (also desktop)

I am creating a server using nodejs and mysql.

in my code I write:

var mysql = require('mysql'); var TEST_DATABASE = 'nodejs_mysql_test'; var TEST_TABLE = 'test'; var client = mysql.createClient({ user: 'root', password: 'root', }); client.query('CREATE DATABASE '+TEST_DATABASE, function(err) { if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) { throw err; } }); 

and the compiler gives me an error: Error: cannot find module 'mysql'

any ideas?

Thank you

+4
source share
3 answers

I think I solved it.

there is a node_modules folder in the nodejs folder in this folder there is a mysql folder. copied it to the folder from which I run my program, and I t work :)

+1
source

This happens when you do not have a module installed, so go to the root of your project and install node -mysql:

 npm install mysql 

You do not need to manually copy the folder yourself, and dependencies are best handled using NPM.

+12
source
  • Go to the project folder .... in my case command line command
  • enter as shown in screenshot

npm install mysql

  1. After installation, you will see the following directories. enter image description here
+1
source

Source: https://habr.com/ru/post/1391152/


All Articles