Search code examples
npmangularbowerbower-installnpm-install

npm/bower - Basic questions(Why it requires for just AngularJS then?)


I read about npm and bower, differences, usage, how it works, purpose as well. All explanation says that to work in NodeJs. But when I searched for AngularJS2, the tutorial says use npm. I have some basic questions based upon the understanding that npm basically for dependency management or packages to be installed.

  1. How my Java/Eclipse workspace knows that npm installed the particular JS library/file, what path should be given in the html/web page for including those files/libraries?
  2. If I move the web application to production, how will the server gets those dependent libraries? Even if server gets it, it might be installed in different folder. Basically how it can be managed with a web applications in different environments for just AngularJS app?

Can anyone please help me to have better understanding?


Solution

  • Finally found the answer. NPM is node package manager which helps basically to download the dependencies (almost like maven, gradle in java).

    npm software needs to be installed in developer's machine.

    Add the required dependencies in the package.json in the root folder of AngularJS application.

    Open the DOS command line and navigate to project root folder(workspace/project in eclipse), then type npm install which will download all the dependencies mentioned in the package.json to a folder called npm_modules inside project folder.

    The other and important advantage is npm can be used to install browser agent as well. So npm start command will open the browser and will load the application automatically in browser. Developer does not need to be aware about NodeJs. One more benefit of using this approach is the browser will get refreshed automatically when any update in the JS file gets saved.