Search code examples
node.jsgitwebservermodule

When the site project files are uploaded to the server, how the project's node modules still work if they usually added to .gitignore?


This is a question from a beginner. Just curious to know how the node modules installed via npm suppose to work on the site uploaded to the server via git if the node modules folders as far as I know and have read, are added to the .gitignore file? These modules are actually impact the site functionality and adding them to .gitignore means they will not be uploaded to the server. So how this works in reality? How the site uploaded to the server still have the functionality and active libraries from the npm modules if they are ignored and not uploaded?


Solution

  • package.json contains all info of dependencies used.

    when you deploy your site somewhere, it checks your package.json file and install required packages.

    as a quick exercise

    1. delete node_modules folder
    2. run npm install . it checks your package.json to satisfy dependencies.
    3. your node_modules folder is back :)