Create a package.json file

A package.json file can be created by using the package manager. So it is as simple as typing npm init in the terminal.


npm init

When initializing, some information is given and questions are asked:


This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install  --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (demoNode)                                                                                
version: (0.0.0)                                                                                    
description: Demo project                                                                 
entry point: (app.js)                                                                         
test command:                                                                                       
git repository:                                                                                     
keywords:                                                                                           
author: Dribbit                                                                                            
license: (ISC)                                                                                      
About to write to /home/jurgen/www/nodeExamples/fileHandling/package.json:

{
  "name": "demoNode",
  "version": "0.0.0",
  "description": "Demo project",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Dribbit",
  "license": "ISC"
}

Now you can add dependencies by using the terminal


npm install optimist --save

Or by adding the dependency directly inside the package.json file


  "dependencies": {
      "optimist": "*"
  },

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.