i am a newbie to nodejs. To connect mysql, i installed mysql
on node using the command,
npm install mysql
I didn't get any error while installing. Then i tried executing the following code,
var mysql = require("mysql");
But it is showing the following error while im trying to execute that.
C:\node\mysql>node app.js module.js:340 throw err; ^ Error: Cannot find module 'mysql' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (C:\node\mysql\app.js:1:75) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10)
I tried some suggestion like installing mysql globally using,
npm install -g mysql
But nothing works. Help please!!!
Please note my working environment,
OS: Windows7 Node version: 0.10.15 NPM version: 1.3.5
{ [Error: Cannot find module '/root/.npm/form-data'] code: 'MODULE_NOT_FOUND' } then you can resolve this issue by executing the command npm install --save form-data.
Navigate to folder /node_modules which is inside the main directory, and install mysql by hitting the following command: sudo npm install mysql This will create a folder called mysql inside the /node_modules folder. Now run your app using node app.js command inside the main folder. It shall work and establish the connection with mysal server.
For TypeScript users, if you are importing a built-in Node module (such as http, pathor url) and you are getting an error such as "Cannot find module "x"then the error can be fixed by running npm install @types/node --save-dev
Check if the enviroment variable NODE_PATH is set correctly and pointing to the node_modules path. nodejs uses this variable to search for the libraries This error can be encountered if you are require ing a module that has a missing or incorrect main field in its package.json.
I just ran into the same problem and found it was because the module was installed in:
./node_modules/node-mysql/node_modules/
So, I just moved them all:
mv ./node_modules/node-mysql/node_modules/* ./node_modules/
My node
is installed in C:\some-dir\nodejs-0.10.35\
First navigate to the same directory node
installed: cd C:\some-dir\nodejs-0.10.35
Then npm install mysql
I put my applications in the same directory: C:\some-dir\nodejs-0.10.35\applications\demo.js
It works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With