0
0
Node.jsframework~10 mins

Built-in modules overview 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 built-in 'fs' module in Node.js.

Node.js
const fs = require('[1]');
Drag options to blanks, or click blank then click option'
Afs
Bhttp
Cpath
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'fs' to import the file system module.
Forgetting to use quotes around the module name.
2fill in blank
medium

Complete the code to create a server using the built-in 'http' module.

Node.js
const http = require('http');
const server = http.[1]((req, res) => {
  res.end('Hello');
});
Drag options to blanks, or click blank then click option'
Alisten
Bget
Crequest
DcreateServer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'createServer' to create the server.
Confusing 'request' or 'get' with server creation.
3fill in blank
hard

Fix the error in the code to read a file asynchronously using the 'fs' module.

Node.js
const fs = require('fs');
fs.readFile('file.txt', '[1]', (err, data) => {
  if (err) throw err;
  console.log(data.toString());
});
Drag options to blanks, or click blank then click option'
Autf8
Bbuffer
Creadable
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'buffer' or 'text' which are not valid encoding options.
Omitting the encoding and getting raw buffer data.
4fill in blank
hard

Fill both blanks to import the 'path' module and join two paths.

Node.js
const [1] = require('[2]');
const fullPath = path.join('folder', 'file.txt');
Drag options to blanks, or click blank then click option'
Apath
Bfs
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fs' or 'http' instead of 'path' for path operations.
Mismatching variable name and module name.
5fill in blank
hard

Fill all three blanks to import the 'os' module, get the platform, and print it.

Node.js
const [1] = require('[2]');
const platform = os.[3]();
console.log(platform);
Drag options to blanks, or click blank then click option'
Aos
Cplatform
Dtype
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'type()' instead of 'platform()' to get the OS platform.
Mismatching variable and module names.