0
0
Javascriptprogramming~10 mins

Running JavaScript using 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 print 'Hello, Node.js!' to the console.

Javascript
console.[1]('Hello, Node.js!');
Drag options to blanks, or click blank then click option'
Alog
Bprint
Cwrite
Decho
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' or 'echo' which are not valid console methods in JavaScript.
Trying to use 'write' which is not a console method.
2fill in blank
medium

Complete the command to run a JavaScript file named 'app.js' using Node.js.

Javascript
node [1]
Drag options to blanks, or click blank then click option'
Aapp.js
Brun
Cstart.js
Dindex.js
Attempts:
3 left
💡 Hint
Common Mistakes
Typing 'run' after node which is not needed.
Using a different file name than the one given.
3fill in blank
hard

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

Javascript
const fs = require([1]);
Drag options to blanks, or click blank then click option'
A'file-system'
B'fs'
C'filesystem'
D'fs-module'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module names like 'file-system' or 'filesystem'.
Forgetting to put the module name inside quotes.
4fill in blank
hard

Fill both blanks to create a simple HTTP server using Node.js.

Javascript
const http = require('http');
const server = http.[1]((req, res) => {
  res.[2]('Hello World');
});
Drag options to blanks, or click blank then click option'
AcreateServer
Bsend
Cwrite
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'createServer' for the first blank.
Using 'send' which is not a method on the response object in Node.js.
5fill in blank
hard

Fill all three blanks to start the server listening on port 3000 and log a message.

Javascript
server.[1](3000, () => {
  console.[2]('Server is running on port ' + [3]);
});
Drag options to blanks, or click blank then click option'
Alisten
Blog
C3000
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' instead of 'listen' to start the server.
Using 'print' or other console methods instead of 'log'.
Not using the port number variable or value correctly.