{"id":13624790,"url":"https://github.com/nodejitsu/require-analyzer","last_synced_at":"2025-07-19T03:33:08.824Z","repository":{"id":57354244,"uuid":"1655454","full_name":"nodejitsu/require-analyzer","owner":"nodejitsu","description":"Determine the set of requirements for a given node.js file, directory tree, or module","archived":false,"fork":false,"pushed_at":"2018-03-27T11:51:58.000Z","size":162,"stargazers_count":152,"open_issues_count":5,"forks_count":11,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-26T04:04:57.411Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://github.com/nodejitsu/require-analyzer","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodejitsu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-04-24T01:46:03.000Z","updated_at":"2024-02-29T20:21:13.000Z","dependencies_parsed_at":"2022-09-12T04:01:21.535Z","dependency_job_id":null,"html_url":"https://github.com/nodejitsu/require-analyzer","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejitsu%2Frequire-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejitsu%2Frequire-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejitsu%2Frequire-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejitsu%2Frequire-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodejitsu","download_url":"https://codeload.github.com/nodejitsu/require-analyzer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047646,"owners_count":20389206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T21:01:46.476Z","updated_at":"2025-03-17T14:13:19.638Z","avatar_url":"https://github.com/nodejitsu.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# require-analyzer\n\nDetermine dependencies for a given node.js file, directory tree, or module in code or on the command line\n\n# Status\n[![Build Status](https://secure.travis-ci.org/nodejitsu/require-analyzer.png)](http://travis-ci.org/nodejitsu/require-analyzer)\n\n## Installation\n\n### Installing npm (node package manager)\n\u003cpre\u003e\n  curl http://npmjs.org/install.sh | sh\n\u003c/pre\u003e\n\n### Installing require-analyzer\n\u003cpre\u003e\n  [sudo] npm install require-analyzer\n\u003c/pre\u003e\nNOTE: If you're using `npm \u003e= 1.0` then you need to add the `-g` parameter to install `require-analyzer` globally.\n\n## Usage\nThere are two distinct ways to use the `require-analyzer` library: from the command line or through code. The command line tool is designed to work with `package.json` files so make sure that you have created one for your project first. Checkout [jitsu][0] for a quick and easy way to create a package.json.\n\nFor more information read our blog post at [blog.nodejitsu.com][1].\n\n### Command-line usage\nUsing require-analyzer from the command line is easy. The binary will attempt to read the `package.json` file in the current directory, then analyze the dependencies and cross reference the result.\n\u003cpre\u003e\n  $ require-analyzer --help\n  usage: require-analyzer [options] [directory]\n\n  Analyzes the node.js requirements for the target directory. If no directory\n  is supplied then the current directory is used\n\n  options:\n    --update     Update versions for existing dependencies\n    -h, --help   You're staring at it\n\u003c/pre\u003e\n\nHere's a sample of `require-analyzer` analyzing its own dependencies:\n\u003cpre\u003e\n  $ require-analyzer\n  info:  require-analyzer starting in /Users/Charlie/Nodejitsu/require-analyzer\n  warn:  No dependencies found\n  info:  Analyzing dependencies...\n  info:  Done analyzing raw dependencies\n  info:  Retrieved packages from npm\n  info:  Additional dependencies found\n  data:  {\n  data:    findit: '\u003e= 0.0.3',\n  data:    npm: '\u003e= 0.3.18'\n  data:  }\n  info:  Updating /Users/Charlie/Nodejitsu/require-analyzer/package.json\n  info:  require-analyzer updated package.json dependencies\n\u003c/pre\u003e\n\n### Programmatic usage\nThe easiest way to use `require-analyzer` programmatically is through the `.analyze()` method. This method will use `fs.stat()` on the path supplied and attempt one of three options:\n\n1. If it is a directory that has a package.json, analyze `require` statements from `package.main`\n2. If it is a directory with no package.json analyze every `.js` or `.coffee` file in the directory tree\n3. If it is a file, then analyze `require` statements from that individual file.\n\nLets dive into a quick sample usage:\n\n```javascript\n  var analyzer = require('require-analyzer');\n\n  var options = {\n    target: 'path/to/your/dependency' // e.g /Users/some-user/your-package\n    reduce: true\n  };\n\n  var deps = analyzer.analyze(options, function (err, pkgs) {\n    //\n    // Log all packages that were discovered\n    //\n    console.dir(pkgs);\n  });\n\n  //\n  // The call the `.analyze()` returns an `EventEmitter` which outputs\n  // data at various stages of the analysis operation.\n  //\n  deps.on('dependencies', function (raw) {\n    //\n    // Log the raw list of dependencies (no versions)\n    //\n    console.dir(raw);\n  });\n\n  deps.on('search', function (pkgs) {\n    //\n    // Log the results from the npm search operation with the current\n    // active version for each dependency\n    //\n    console.dir(pkgs);\n  });\n\n  deps.on('reduce', function (reduced) {\n    //\n    // Logs the dependencies after they have been cross-referenced with\n    // sibling dependencies. (i.e. if 'foo' requires 'bar', 'bar' will be removed).\n    //\n    console.dir(reduced);\n  });\n```\n\n### Further analyzing dependencies\nSometimes when dealing with dependencies it is necessary to further analyze the dependencies that are returned. `require-analyzer` has a convenience method for doing just this:\n\n```javascript\n  var analyzer = require('require-analyzer');\n\n  var current = {\n    'foo': '\u003e= 0.1.0'\n  };\n\n  var updated = {\n    'foo': '\u003e= 0.2.0',\n    'bar': '\u003e= 0.1.0'\n  };\n\n  var updates = analyzer.updates(current, updated);\n\n  //\n  // This will return an object literal with the differential\n  // updates between the two sets of dependencies:\n  //\n  // {\n  //   added: { 'bar': '\u003e= 0.1.0' },\n  //   updated: { 'foo': '\u003e= 0.2.0' }\n  // }\n  //\n```\n\n## Tests\n\u003cpre\u003e\n  npm test\n\u003c/pre\u003e\n\n#### Author: [Charlie Robbins][2]\n\n[0]: http://github.com/nodejitsu/jitsu\n[1]: http://blog.nodejitsu.com/analyze-nodejs-dependencies-like-magic\n[2]: http://nodejitsu.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodejitsu%2Frequire-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodejitsu%2Frequire-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodejitsu%2Frequire-analyzer/lists"}