Posts

Showing posts from October, 2021

node required package example code.

<!--use the install package in npm-->   const   jokes  =  require ( "give-me-a-joke" ); const   colors  =  require ( "colors" ); <!--call the package in variable and use the Variable "jokes" and the inbuilt method " getRandomDadJoke" built your function to call them (joke) rainbow as method. jokes . getRandomDadJoke ( function  ( joke ) {      console . log ( joke . rainbow ) }); Detect the language. const   franc  =  require ( "franc" ); const   langs  =  require ( "langs" ); const   input  =  process . argv [ 2 ]; const   langCode  =  franc ( input ); if  ( langCode  ===  'und' ) {      console . log ( "Sorry, We  were not able to get our best...!!!" ) } else  {      const   language  =  langs . where ( "3" ,  langCode ); ...

To create folder and file by the node js, give the command by cmd.

To create folder and file by the node js, give the command by cmd. <!--define the filesystem as constant--> const   fs  =  require ( 'fs' ); <!-- read command from the cmd by process, argv[2] get the string in array--> const   filename  =  process . argv [ 2 ] ||  'Project' ; <!--make the folder and have a call back method.--> // fs.mkdir('apple', { recursive: true }, (err) => { //     console.log("in the callback") //     if (err) throw err; // }); try  {      fs . mkdirSync ( filename ); // create folder without callback      fs . writeFileSync ( ` ${ filename } /index.html` ,  '' ) //create a file      fs . writeFileSync ( ` ${ filename } /app.js` ,  '' )      fs . writeFileSync ( ` ${ filename } /style.css` ,...