I have a node-mysql program
node db.js
module.js: 340
throw err;
Error: Cannot find module 'mysql'
the error is @
var mysql = require('mysql'); //for node-mysql
The error goes away and it all works when I run the program in the nodemodules/node-mysql/ directory, which is sort of lame, considering the other packages I have used are nothing like that, I think.
Is it deliberate for security purposes or am I doing it wrong?
I am damn near certain this question has been asked before, however I couldn't find an actual answer when I searched.
You mixed up two different MySQL packages:
node-mysql
, installed with npm install node-mysql
;mysql
, installed with npm install mysql
, and on GitHub confusingly called node-mysql
;You installed the first one, which installs in node_modules/node-mysql/
and should be loaded using require('node-mysql')
.
If you install the second one (which I think you want, anyway), it'll install in node_modules/mysql/
and your code will work as expected.