Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Start project with npm init - Node.js

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 564
    Comment on it

    NPM's init command will scaffold out a valid json file for you project.

    The commands for npm init are:-

    mkdir myapis
    cd myapis
    npm init --yes

    I have used --yes option with the above command, because I don't want to set author name, keywords, git urls etc. for the project. If you need to setup all these details you can use

    npm init without --yes

    The above command will create package.json file at the root level with content:


     

    {
      "name": "myapis",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC"
    }

     
    The first thing you  do is, specify 'engines' key with your keyword in package.json:

    User ( node -v ) bto check the version of node installed.

    "engines": {
      "node": "6.2.2"
    }
    
    

    Use a .npmrc

    By default, npm doesn't save installed dependencies to package.json. You need to do it manually like as follows:

    npm install moment --save

    --save flag is used to auto update package.json.

    Even better, you can set these options in .npmrc file, as follows:-

     npm config set save=true
    
     npm config set save-exact=true
    
     cat ~/.npmrc

     

     Now, npm install moment, will automatically add moment to package.json.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: