DEV Community

ChuangWANG
ChuangWANG

Posted on

package.json

What we need to create a NPM project in a dir is creating package.json file in the root dir.

1.Create package.json by npm init -y

Than a package.json file be created in the root dir.
package.json

{
  "name": "testet",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Today is a good day.\""
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Enter fullscreen mode Exit fullscreen mode

Note: don't add comment in package.json scripts fragment

run scripts that note in package.json

npm run test
Enter fullscreen mode Exit fullscreen mode

The output:

PS C:\Users\89104\Desktop\testet> npm run test

> testet@1.0.0 test C:\Users\89104\Desktop\testet
> echo "Today is a good day."

"Today is a good day."
Enter fullscreen mode Exit fullscreen mode

2.Write a package.json hand by hand

{
    "scripts": {
        "test": "echo \"Today is a good day\""
    }
}
Enter fullscreen mode Exit fullscreen mode

Creating package.json by hand is not a good way, Because the package.json right farmat is more complicte. Some time the package.json can not service npm run xxxx

Create package.json with first way, do not by second way.

Discussion (0)