← Back to Node.js Course | Chapter 3: npm & Packages | Lesson 1 of 7

package.json का परिचय

package.json आपके project का ID card है: इसका name, version, scripts, और dependencies।

In this page:

  1. package.json
Syntax
javascript
{
  "name": "package-name",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {}
}

package.json

File metadata (name, version, description), entry point main, custom scripts, और dependency maps list करती है। npm packages install करने और scripts चलाने के लिए इसे पढ़ता है। type को module set करना .js files को ES modules में switch कर देता है।

Note: जल्दी से एक starter file generate करने के लिए npm init -y चलाएँ।

उदाहरण: package.json

javascript
const pkg = {
  name: "demo-app",
  version: "1.0.0",
  main: "index.js",
  scripts: { start: "node index.js", test: "node --test" },
  dependencies: { express: "^4.19.2" },
  devDependencies: { nodemon: "^3.1.0" },
};
console.log(JSON.stringify(pkg, null, 2));
console.log("scripts:", Object.keys(pkg.scripts));

// Output:
// {
//   "name": "demo-app",
//   "version": "1.0.0",
//   "main": "index.js",
//   "scripts": {
//     "start": "node index.js",
//     "test": "node --test"
//   },
//   "dependencies": {
//     "express": "^4.19.2"
//   },
//   "devDependencies": {
//     "nodemon": "^3.1.0"
//   }
// }
// scripts: [ 'start', 'test' ]

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. trailing commas या comments के साथ invalid JSON लिखना
  2. scripts entry भूल जाना
  3. default test script छोड़ना जो हमेशा fail होता है
चैप्टर सारांश
  • package.json project describe करता है
  • scripts npm run commands define करते हैं
  • dependencies नाम और range से listed हैं
  • type module format control करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.