Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Last active March 5, 2022 20:28
Show Gist options
  • Select an option

  • Save sandrabosk/fdbf06e18f9f1d8992435877c707311a to your computer and use it in GitHub Desktop.

Select an option

Save sandrabosk/fdbf06e18f9f1d8992435877c707311a to your computer and use it in GitHub Desktop.

How to use npm - demo

$ mkdir npm-getting-started #1
$ cd npm-getting-started #2
$ npm init --yes #3

npm init --yes initializes a default package.json. if you plan to use at least one npm package, you will have to have package.json.

$ npm install colors # or npm i colors #4
$ touch index.js #5
$ code . #6
// index.js

// https://www.npmjs.com/package/colors

// you need to install and to require package so your app knows where you want to use it
const colors = require('colors/safe');
 
console.log(colors.green('hello')); // outputs green text
console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text
console.log(colors.inverse('inverse the color')); // inverses the color
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
console.log(colors.trap('Run the trap')); // Drops the bass
$ node index.js #7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment