0
0
Node.jsframework~10 mins

What is Node.js in Node.js - Interactive Quiz & 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 HTTP module in Node.js.

Node.js
const http = require([1]);
Drag options to blanks, or click blank then click option'
A"fs"
B"http"
C"path"
D"express"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fs' which is for file system operations.
Using 'express' which is a third-party framework, not built-in.
2fill in blank
medium

Complete the code to create a simple HTTP server that listens on port 3000.

Node.js
http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World');
}).[1](3000);
Drag options to blanks, or click blank then click option'
Astart
Bopen
Clisten
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' which is not a method of the server object.
Using 'run' which is not valid here.
3fill in blank
hard

Fix the error in the code to correctly import the 'fs' module.

Node.js
const fs = require([1]);
Drag options to blanks, or click blank then click option'
A"fs"
B"file-system"
C"filesystem"
D"fileSystem"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'file-system' which is not a built-in module name.
Using camelCase or other variations.
4fill in blank
hard

Fill both blanks to create a server that responds with JSON data.

Node.js
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': [1] });
  res.end(JSON.stringify({ message: [2] }));
});
Drag options to blanks, or click blank then click option'
A"application/json"
B"Hello"
C"text/plain"
D"World"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text/plain' as content type when sending JSON.
Putting the content type value without quotes.
5fill in blank
hard

Fill all three blanks to export a function named 'startServer' from a module.

Node.js
function [1]() {
  console.log('Server started');
}

module.exports = [2] = [3];
Drag options to blanks, or click blank then click option'
AstartServer
DserverStart
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for function and export.
Using camelCase incorrectly.