Should node-gyp be installed globally and locally? - node.js

I am looking at nodejs addon examples at https://github.com/nodejs/abi-stable-node-addon-examples.
The read-me section says that I must install node-gyp globally:
$ sudo npm install node-gyp -g
However, after installing node-gyp globally, does one also need to install it within the local project?
$ cd myproject
$ npm install node-gyp

It is good to install the node-gyp globally because main purpose of the node-gyp is to build the node native modules. node-gyp also need some tool like visual studio (in case of building on Windows)
and python which also installed globally.
after install globally no need to install it locally.

Related

Installing lodash.filter

What is the difference between npm install and npm install --save?
I try to install lodash.filter using npm install --save lodash.filter. I thought it install the packet + describes it in package.json.
But the system says, she do not understand, what lodash.filter is.
Should I install lodash.filter again using npm install lodash.filter? Or what should I do? Uninstalling lodash.filter and trying to install it again?
To check installed modules use npm ls to show all your modules and npm ls lodash.filter to see, if it is installed. I think the system showed the mistake, because imported lodash.filter wasn't used in program (I followed the other steps in the tutorial and it rendered well).

Error: Cannot find module 'ffi' compiling ElectronJS project

I'm new on NodeJS/ElectronJS.
I need to use User.dll functions.
My actual situation is:
Windows 10 on Parallels
Node -v = 10.15.3 (LTS)
NPM -v = 6.9.0
I installed:
npm install --global --production windows-build-tools
npm install win32-api
npm install ffi (gives me several "\ffi.cc(***): warning C4996: 'v8::Value::To Object': .... deprecated)
I added var FFI = require('node-ffi'); in my "main.js" and when I try to compile with npm start
I obtain this error:
Error: Cannot find module 'node-ffi' at Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
What's wrong?
The following steps fixed my issue (major pain in the ***)
Make sure the node gyp compiler is installed
npm install -g node-gyp
Install the FFI package into the local project
npm install --save ffi
I also needed to install ref-array (part of example code)
npm install ref-array --save
Go into the node_modules/ffi directory and do an NPM install to make sure it's got all it's dependencies
cd node_modules/ffi
npm install
Get back out of the node_modules/ffi folder
cd ../../
Install the electron rebuild tools
npm install --save-dev electron-rebuild
Run the electron rebuild script (I'm running on Windows, hence .cmd)
.\node_modules\.bin\electron-rebuild.cmd
So simple (NOT) :D
Solved with this:
How do I resolve "Cannot find module" error using Node.js?
using npm install
and then
Node - was compiled against a different Node.js version using NODE_MODULE_VERSION 51
using
./node_modules/.bin/electron-rebuild

Install packages locally with npm

I am new with Node and npm, and when I try to install packages locally, all of the dependencies for that specific package gets installed in the main nodule_modules folder.
It looks like this
LOCALLY
And if I install them globally it looks like this
GLOBALLY
I think I should mention the fact that the folder where I try to install locally is on Desktop.
If you need to install specific dependancies for a project you are working on then do it locally:
npm install <packagename>
If you need something that you can run from the commandline such as grunt or phantomjs (etc..) then install it globally:
npm install -g <packagename>

npm install from package.json, the dependancy -v yields command not found

Reinstalled node/npm from scratch and after npm install I can see the node_modules folder with all of the content from package.json. Checking gulp -v gives command not found in the command line on a mac. If I install gulp globally, gulp -v yields the version.
Is there a way of not installing all dependancies globally to use?
Generally gulp is a package which is used to run some task. These task might need to have administrator privileges. So it is better to install it globally using "npm install -g gulp" command. Here -g means "install it globally".
npm install installs the package locally.

installing grunt locally as under privileged user

I'm using node/grunt for deploying to a shared hosting server.
I have node installed in $HOME/opt/node
I don't know where npm install -g grunt is going to install it to, or how to tell npm to install global files to $HOME/some/path.
I ran npm install grunt -g and it seemed to work, but I cannot find the grunt binary anywhere.
If you want the grunt command in your server's shell, you'll need to install the Grunt CLI.
npm install grunt-cli -g
Global modules are located here:
/usr/local/lib/node_modules

Resources