coreMIDI and NodeJS - node.js

I've installed coreMIDI following this:
sudo npm install -g coremidi
The installation was successful, but I don't understand how to use it using node.js
This is the first line of my code:
var coremidi = require('coremidi')();
But the output is:
Error: Cannot find module 'coremidi'
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> (/Users/[NAME]/Desktop/nodeMidi/coremidi/test1.js:1:78)
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)

The require statement in node looks for a folder named node_modules in the current folder and if that exists looks in there for a folder named after your package. If it isn't found, it goes one directory higher and tries that again. It'll keep doing this until it reached the root folder of your file system.
The reason it can't find coremidi is because coremidi has been installed in the global node_modules folder since you used the -g flag. This is OS/node install dependent, but usually something like /usr/lib/local/share/npm/ or whatever. Since this path
You shouldn't use -g to install npm modules unless they're specifically meant to be installed globally (usually that means that include a script for you to run, like NPM itself, or jshint, or mocha, or tap, or etc...)

Related

Error: Cannot find module 'pg', after running npm install pg

Using VSCode. Installed latest Node.js (first time user) for Windows, and the desired modules, one of which was 'pg' (npm install pg)
At the top of my script I have this:
const pg = require('pg');
When i attempt to debug, I get this error when it hits that line:
Exception has occurred: Error
Error: Cannot find module 'pg'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (c:\EBI\Work\Node-pg-log\get_pg_log.js:3:12)
at Module._compile (module.js:649:14)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Is there something else I need to install or set up? Debugging is in place.
This usually happens when node_modules/ folder is located in some sub-directory. Like
/app
----index.js
----/libs
--------/node_modules/
You want a directory structure like
/app
----index.js
----node_modules/
Where node_modules folder is either in the current directory or in some upper level directory
If you are using TypeScript it is necessary to install pg types. Use the command
npm install --save-dev #types/pg

nodejs - can't find module Backbone

var Backbone = require('backbone');
causes this error:
module.js:340
throw err;
^
Error: Cannot find module 'backbone'
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:\Users\denman\workspace-nodejs\AFirstServer_NodeUpAndRunning\hello-world-server.js:6:16)
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)
how can this be?
I installed Backbone via npm install -g backbone
I even restarted Eclipse and my machine.
By default, node will not load modules that are installed globally. You should be performing any npm install-s in your project's directory root, not installing them globally.
Try this instead. Create your new project directory, change to it, and then:
npm init #this will create a package.json for your project
npm install --save backbone # this will install backbone to the directory, and save it into your package.json as a dependency
Then create a file in that directory called index.js. Put your code in there requiring backbone. Then from within that directory run node index.js, and you'll find that everything works, and backbone is available.
Here is a good blog post on the subject.

npm doesn't work on an ARM embedded device

I installed Node.js on an embedded device running with a core Linux 3.0.
When I try to execute npm to install some modules, I get the follow issue :
DM-37x# npm
module.js:340
throw err;
^
Error: Cannot find module 'npmlog'
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 /usr/local/bin/npm:18:11
at Object.<anonymous> (/usr/local/bin/npm:86:3)
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)
I already tried to reinstall node.js but the bug is still here.
How can I do to fix this problem?
Try installing (or reinstalling) npmlog.
See https://www.npmjs.org/package/npmlog
Make sure you have a package.json file in the top level of your project directory (each project).
Use npm ls
and
npm update
to make sure the npmlog package is included.

node.js returns "Cannot find module 'lockit-mongodb-adapter'"

I am going through my first node.js project. I've installed lockit , have a app.js file, and when I try to run it I get this error
module.js:340
throw err;
^ Error: Cannot find module 'lockit-mongodb-adapter'
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 new module.exports (C:\Users\xx\Documents\mailer\index.js:38:44)
at Object.<anonymous> (C:\Users\xx\Documents\mailer\examples\mongodb\app. js:32:14)
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)
I am quite certain I have lockit-mongodb-adapter installed.
You need to install the module. Cd to the root of your app directory and run this command and make sure lockit-mongodb-adapter is in your node modules directory.
npm install lockit-mongodb-adapter
Another thing you can do if you are certain it is installed is double check to see what is installed by running this command:
npm list
And this one to see what is installed globally:
npm list -g
Update:
I was able to reproduce the issue you where having. And to resolve it I deleted the module from the node moules directory. And re-installed with the following command:
npm install lockit-mongodb-adapter -save
It now shows up in npm list with no issues:

Apparently I deleted some of the files on the node_module, how can I restore them?

I was trying to install node trough brew and it was giving a lot of errors, and apparently some file was not giving the permission, so I thunked that the file was from other failed try to intall node and I decide to remove the directory. It failed to remove the dir and the files, but apparently some had been erased.
They are:
module.js:340
throw err;
^
Error: Cannot find module 'child-process-close'
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 /usr/local/lib/node_modules/npm/lib/npm.js:15:1
at Object. (/usr/local/lib/node_modules/npm/lib/npm.js:461:3)
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)
How can I solve this? I just wanted to try sails.js for fun, but I didn't see any fun time yet, only problems.
Thank you
It appears that your issue is not with the sails global or project installation, but rather that you corrupted the nodejs installation. I'd recommend you to just download nodjs again from nodejs.org (this downloads a .pkg) and install it with that package.
If this complains about permissions and overwriting things (which I don't think), try first deleting the whole node_modules folder with sudo:
sudo rm -fr /usr/local/lib/node_modules
I know this is super late. However, I was getting this same error while trying get a react native app up and running.
I installed node with HomeBrew and after getting the following:
Error: Cannot find module 'child-process-close'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at /usr/local/lib/node_modules/npm/lib/npm.js:15:1
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:520:3)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
I then ran
brew postinstall node
and got:
Permission denied - /usr/local/lib/node_modules/npm/AUTHORS
So then I ran:
sudo brew postinstall node
and it seemed to work fine. I could go about installing waterline, firebase, or whatever else I tried.
Hope this helps!
Run npm install from your project directory to re-install all modules listed in your package.json.

Resources