Node.js Yarn Package Manager Creating a basic package


Example

The yarn init command will walk you through the creation of a package.json file to configure some information about your package. This is similar to the npm init command in npm.

Create and navigate to a new directory to hold your package, and then run yarn init

mkdir my-package && cd my-package
yarn init

Answer the questions that follow in the CLI

question name (my-package): my-package
question version (1.0.0): 
question description: A test package
question entry point (index.js): 
question repository url: 
question author: StackOverflow Documentation
question license (MIT): 
success Saved package.json
✨  Done in 27.31s.

This will generate a package.json file similar to the following

{
  "name": "my-package",
  "version": "1.0.0",
  "description": "A test package",
  "main": "index.js",
  "author": "StackOverflow Documentation",
  "license": "MIT"
}

Now lets try adding a dependency. The basic syntax for this is yarn add [package-name]

Run the following to install ExpressJS

yarn add express

This will add a dependencies section to your package.json, and add ExpressJS

"dependencies": {
    "express": "^4.15.2"
}