package.json का परिचय
package.json आपके project का ID card है: इसका name, version, scripts, और dependencies।
In this page:
Syntax
{
"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
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. #}
आम गलतियां
- trailing commas या comments के साथ invalid JSON लिखना
- scripts entry भूल जाना
- 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: