What is node-gyp

97,087

node-gyp is a tool which compiles Node.js Addons. Node.js Addons are native Node.js Modules, written in C or C++, which therefore need to be compiled on your machine. After they are compiled with tools like node-gyp, their functionality can be accessed via require(), just as any other Node.js Module.

If you do what you suggested the module won't work, you will need to compile it/build it with node-gyp on the system you moved the program to.

node-gyp: https://github.com/nodejs/node-gyp

Node.js Addons: https://nodejs.org/api/addons.html

Share:
97,087

Related videos on Youtube

selftaught91
Author by

selftaught91

Hi my name is Raj Ranjan from Mumbai, India and I am a Full Stack developer who specializes in both web and mobile development.My core strength lies in providing quality web services, bug free, with in timeline and estimation. I have a 5+ years of experience in web technologies and 2+ years of experience in mobile technologies. Currently I am working as a senior software engineer in Research & Development of Alepo Technologies Mumbai.

Updated on August 25, 2020

Comments

  • selftaught91
    selftaught91 over 3 years

    Can anyone explain me what is node-gyp and why it uses my system files to build Node.JS packages.

    1. If Ii build a node project and it used node-gyp internally.
    2. Then I just tar that project and moved to a different system
    3. I untar it there and try to use it

    Will this approach work?

    • slebetman
      slebetman over 7 years
      It's described on its github page: github.com/nodejs/node-gyp. Basically, node-gyp is like make. It's a tool used to control the compilation process of C++ projects. Only, it's designed specifically for node.js addons (modules written in C++). So moving to a different system may work if it uses the same CPU. Moving to a different OS or CPU (for example from x86 to ARM) won't work. For Linux, moving to a different distro of different version of the same distro may or may not work. I'm not 100% sure if moving to a different version of node.js would work
    • Kzqai
      Kzqai about 4 years
      When I run yarn why node-gyp it comes back with: because node-sass, so I'm sure it has other uses, but it may be in your project if you or someone you love has been diagnosed with sass.
    • Lukas Liesis
      Lukas Liesis about 4 years
      @slebetman moving to different node version won't work, not sure if that's 100% true, yet from my experience, you need to remove old node-gyp after upgrading nodejs version and during modules install it's re-build automatically in the background.
    • Alper
      Alper over 2 years
      Why is it always broken?
  • PirateApp
    PirateApp over 5 years
    gotta admit, i see a module no npmjs that uses node-gyp I usually run 10 miles away
  • Jim Aho
    Jim Aho over 5 years
    It's exciting that you nowadays can clone a (what seems) relatively simple web app written in NodeJS, and all of a sudden you must download software to compile native coden written in C and C++. The best part is when you run into problems, and you know exactly what do with your web design skills to solve this.
  • Mr-Programs
    Mr-Programs over 5 years
    so you can basically use node-gyp to run ANY c/c++ code? is this transformed to javascript or executed as it is and connected through a binding?
  • vuza
    vuza over 5 years
    @Mr-Programs It is connected through a binding, which also needs to be written by you
  • Adam Tolley
    Adam Tolley over 4 years
    @JimAho Ideally, and often, the code is just black-boxed. The good is that you can use fast and well supported tools to do specific things like parse xml, and not have to wait for a js port which might be slower or more broken. That said, I prefer native js whenever possible, but I'm not certain that position is well founded. Also, C/C++ should be very portable for any case that is not purposefully OS dependent (like notifications). Furthermore, bug prone packages don't see wide adoption regardless of the source of said bugs.
  • Tom
    Tom over 4 years
    FYI, I believe "gyp" is short for "generate your projects"
  • Timo
    Timo almost 3 years
    @PirateApp I do not understand, can you please explain in other words? Your comment is high in rep, so I want to know it - you do not like node-gyp and run away?
  • PirateApp
    PirateApp almost 3 years
    node-gyp creates native dependencies and making it work on an external environment like docker or a virtual machine seems like a pain, take bcrypt.js it certainly works much faster if you use the native one but due to it being a pain, i switched to bcryptjs that doesnt require node-gyp
  • jiajianrong
    jiajianrong about 2 years
    Good answer. Still one thing bothers me: why the ealier Java says 'write once run everywhere', but the nodejs still uses C/C++ add-ons?
  • MetaSean
    MetaSean almost 2 years
    @jiajianrong - Well, you sort of answered your own question, Java's claim was 'write once run everywhere'. JavaScript, i.e. the "js" in "node.js" never made such a claim. JavaScript was initially designed to add interactivity to a specific browser (i.e. Netscape) but became the defacto language for all browser activity. nodejs brought that language to environments other than browsers, and in doing so, it is clearly going to have to interact with those additional environments. node-gyp is an attempt to provide some cross-environment compatibility.