In this segment, you will learn how to search for packages in the npm repository. You will see one such package named chalk in action.
In the video above, you learnt about the chalk package. You first installed this package using the following command:
npm install chalk
Then, you imported this package using the 'require' function. After that, using the properties present in this package, you printed the text "Hello World" in blue.
The code that you looked at in the video is given below:
const chalk = require('chalk'); console.log(chalk.blue('Hello world!'));
Output:
Hello World
(in blue color)
In the next video, you will learn more about this package.
The code that you looked at in the video is given below:
const chalk = require('chalk'); const success = chalk.green; const error = chalk.red.underline; const warning = chalk.yellow; console.log(success('Task Done!')); console.log(error('Something went wrong!')); console.log(warning('Check your code again!')); console.log(error('Error occurred!'));
Output:
Task Done! Something went wrong! Check your code again! Error occurred!
('Task Done!' is printed in green color.
'Something went wrong!' is printed in red colour and is underlined.
'Check your code again!' is printed in yellow color.
'Error occurred!' is printed in red colour and is underlined.)
In this segment, you looked at a popular package named chalk, which is used to format text, and using this package, you printed the text in different colours and also defined your own themes.