Start A New Nodejs Program

  • mkdir program name
  • npm init
    • this will create package.json
    • if using Git, install Git first before this step.  Otherwise, package.json will not be completely reflect what’s required in the Git repository
    • default entry point is index.js
  • npm install library –save
    • package.json will be updated to have the installed library as part of dependency
  • Packages that are used for the development of a project but not for building or running it in production are called development dependencies. They are not necessary for your module or application to work in production, but may be helpful while writing the code.
      • example: code linter
      • npm i eslint@6.0.0 --save-dev
        
      • this will show up in the devDependencies section in package.json
  • While the package.json file lists dependencies that tell us the suitable versions that should be installed for the project, the package-lock.json file keeps track of all changes in package.json or node_modules and tells us the exact version of the package installed.
  • listing installed modules to specified depth
    • npm -ls –depth 1
  • see outdated modules
    • npm outdated
  • update modules
    • npm up library or just npm up for all library
  • uninstall modules
    • npm un library
  • npm provides an audit command to highlight potential security risks in your dependencies
    • npm audit
    • npm audit fix
  • reference: https://www.digitalocean.com/community/tutorials/how-to-use-node-js-modules-with-npm-and-package-json