0
0
Node.jsframework~10 mins

execFile for running executables in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the execFile function from the child_process module.

Node.js
const { [1] } = require('child_process');
Drag options to blanks, or click blank then click option'
Afork
Bexec
Cspawn
DexecFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exec' instead of 'execFile'.
Trying to import the whole module without destructuring.
2fill in blank
medium

Complete the code to run the executable 'ls' with execFile.

Node.js
execFile('[1]', (error, stdout, stderr) => {
  if (error) {
    console.error(error);
    return;
  }
  console.log(stdout);
});
Drag options to blanks, or click blank then click option'
Anpm
Bnode
Cls
Dgit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' or 'npm' which are not simple executables for listing files.
Using 'git' which is for version control.
3fill in blank
hard

Fix the error in the callback parameter to correctly handle the error.

Node.js
execFile('ls', ([1], stdout, stderr) => {
  if (error) {
    console.error(error);
    return;
  }
  console.log(stdout);
});
Drag options to blanks, or click blank then click option'
Aerr
Berror
Ce
Dexception
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the variable used inside the callback.
Using 'err' or 'e' but checking 'error' inside the function.
4fill in blank
hard

Fill both blanks to run 'node' with arguments to execute a script file 'app.js'.

Node.js
execFile('[1]', ['[2]'], (error, stdout, stderr) => {
  if (error) {
    console.error(error);
    return;
  }
  console.log(stdout);
});
Drag options to blanks, or click blank then click option'
Anode
Bapp.js
Cindex.js
Dscript.js
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong executable name like 'npm'.
Using wrong script file names.
5fill in blank
hard

Fill all three blanks to run 'git' with arguments to show the current branch name.

Node.js
execFile('[1]', ['[2]', '[3]'], (error, stdout, stderr) => {
  if (error) {
    console.error(error);
    return;
  }
  console.log(`Current branch: ${stdout.trim()}`);
});
Drag options to blanks, or click blank then click option'
Agit
Bbranch
C--show-current
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of '--show-current'.
Using wrong executable or arguments.