node, npm and yarn tasks

Setup

Get node and yarn installed

If you'd like to do this on your own computer follow the instructions here.

Otherwise you can use repl.it

1. Create a new yarn project

Run

mkdir project
cd project
yarn init

yarn init will ask you lots of questions, you can either type your answer to each question and press 'enter', or just press 'enter' multiple times to accept the defaults.

2. Install lodash into the project

yarn add lodash

3. Enable import on node

Modify the package.json by adding the following key value pair at anywhere at the top level of the JSON object:

"type": "module",

This allows you to use import statements.

4. Create a file random.js inside the project/ folder

import the lodash module as _.

and then: console.log(_.random(100)) which logs a random number between 0 and 100.

Then run your program using node random.js

5. Install prettier as a dev dependency

yarn add prettier --dev

6. Add a script to your package.json.

Add a script "format" in your package.json which calls: prettier --write random.js

Then call your script using yarn run format