Luke
Luke

Reputation: 21236

Install MySQL support for Node JS

I'm trying to install MySQL support for NodeJS (v0.6.9) on Ubuntu. I'm issuing the following commands:

sudo apt-get install libmysqlclient-dev

I get no errors. I then install the module for Node:

sudo npm install -g db-mysql

Again. No errors. However, I do get what looks like a warning:

Checking for node path                   : not found 

But the installation ends with:

'build' finished successfully (1.504s)
[email protected] /usr/local/lib/node_modules/db-mysql

In my program source I now add:

var mysql = require("db-mysql");

But when I run this, I get the following error:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module 'db-mysql'
    at Function._resolveFilename (module.js:334:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:357:17)
    at require (module.js:373:17)
    at Object.<anonymous> (/home/me/projects/node/test.js:4:13)
    at Module._compile (module.js:444:26)
    at Object..js (module.js:462:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:482:10)

It obviously can't find the db-mysql module.

Upvotes: 0

Views: 2464

Answers (1)

Vadim Baryshev
Vadim Baryshev

Reputation: 26199

Node.js does not looking for modules in global modules folder (/usr/local/lib) by default.

You need to install your module locally by npm install db-mysql.

You can read more about module resolving strategy here: http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders

Upvotes: 1

Related Questions