What is package.json in Node.js?

Created Jan 22, 2024Last modified Jan 22, 2024
JavaScriptNode.js

JavaScript Basics


The package.json file is a crucial part of Node.js projects. It contains metadata about the project, as well as configuration details for the project and its dependencies.

Here are the key components of a package.json file:

"name": "lr_grepjs"
"version": "1.0.0"
"description": "A grep-like CLI app in Node.js"
"main": "lib/lr_grep.js"
"scripts": {
  "test": "mocha test/*.js",
  "start": "node lib/lr_grep.js"
}

In this example, running npm test would execute the tests using Mocha, and npm start would run your CLI app.

"keywords": ["grep", "CLI", "Node.js"]
"author": "Your Name"
"license": "MIT"
"dependencies": {
  "some-package": "^1.0.0"
}
"devDependencies": {
  "mocha": "^8.4.0",
  "chai": "^4.3.4"
}
"engines": {
  "node": ">=10.0.0"
}
"repository": {
  "type": "git",
  "url": "https://github.com/yourusername/lr_grepjs.git"
}

Example package.json

{
  "name": "lr_grepjs",
  "version": "1.0.0",
  "description": "A grep-like CLI app in Node.js",
  "main": "lib/lr_grep.js",
  "scripts": {
    "test": "mocha test/*.js",
    "start": "node lib/lr_grep.js"
  },
  "keywords": ["grep", "CLI", "Node.js"],
  "author": "Your Name",
  "license": "MIT",
  "dependencies": {
    "some-package": "^1.0.0"
  },
  "devDependencies": {
    "mocha": "^8.4.0",
    "chai": "^4.3.4"
  },
  "engines": {
    "node": ">=10.0.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/yourusername/lr_grepjs.git"
  }
}