Bird
Raised Fist0
Denoframework~10 mins

Migrating a Node.js project to Deno - Interactive Code Practice

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

Complete the code to import the standard HTTP server module in Deno.

Deno
import { serve } from "https://deno.land/std/http/server.ts"[1]
Drag options to blanks, or click blank then click option'
A:
B;
C.
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma or period instead of a semicolon.
Omitting the semicolon and causing syntax errors.
2fill in blank
medium

Complete the code to start a simple HTTP server in Deno.

Deno
serve(() => new Response("Hello from Deno!"))[1]
Drag options to blanks, or click blank then click option'
A.listenAndServe()
B.listen()
C.start()
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call a non-existent method like .listen().
Omitting the parentheses and not starting the server.
3fill in blank
hard

Fix the error in the import statement to use Deno's URL imports instead of Node.js style.

Deno
import express from '[1]';
Drag options to blanks, or click blank then click option'
A"https://deno.land/x/express"
B"express"
C"./express.js"
D"express/index.js"
Attempts:
3 left
💡 Hint
Common Mistakes
Using Node.js style imports without URLs.
Using relative paths without hosting the module.
4fill in blank
hard

Fill both blanks to convert a Node.js callback style function to a Deno async function.

Deno
async function readFile() {
  const data = await Deno.[1]("file.txt", { [2]: "utf8" });
  return data;
}
Drag options to blanks, or click blank then click option'
AreadTextFile
BreadFileSync
Cencoding
DreadFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous methods in async functions.
Using incorrect option names like format instead of encoding.
5fill in blank
hard

Fill all three blanks to rewrite a Node.js environment variable access to Deno style.

Deno
const port = Deno.[1].[2]([3]) || 8080;
Drag options to blanks, or click blank then click option'
Aenv
Bget
C"PORT"
Dprocess
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use process.env.PORT like in Node.js.
Not using quotes around the environment variable name.

Practice

(1/5)
1. Which of the following is a key difference when migrating a Node.js project to Deno?
easy
A. Deno uses CommonJS modules by default.
B. Deno uses URL imports instead of npm packages.
C. Deno requires no code changes from Node.js.
D. Deno automatically grants all permissions to the code.

Solution

  1. Step 1: Understand module import differences

    Node.js uses npm packages imported by name, while Deno uses direct URL imports.
  2. Step 2: Check permission handling and module system

    Deno requires explicit permission grants and uses ES modules, not CommonJS.
  3. Final Answer:

    Deno uses URL imports instead of npm packages. -> Option B
  4. Quick Check:

    Module import style = D [OK]
Hint: Remember: Deno imports modules via URLs, not npm names. [OK]
Common Mistakes:
  • Assuming Deno uses npm packages directly
  • Thinking Deno grants permissions automatically
  • Believing Node.js code runs unchanged in Deno
2. Which syntax correctly imports the lodash library in Deno?
easy
A. import _ from 'https://cdn.skypack.dev/lodash';
B. const _ = require('lodash');
C. import _ from 'lodash';
D. import _ from 'npm:lodash';

Solution

  1. Step 1: Identify Deno import style

    Deno imports modules using URLs, not package names or require().
  2. Step 2: Check each option

    import _ from 'https://cdn.skypack.dev/lodash'; uses a valid URL import from a CDN, which is correct for Deno.
  3. Final Answer:

    import _ from 'https://cdn.skypack.dev/lodash'; -> Option A
  4. Quick Check:

    URL import syntax = C [OK]
Hint: Use full URLs for imports in Deno, not package names. [OK]
Common Mistakes:
  • Using require() which is Node.js only
  • Importing by package name without URL
  • Using npm: prefix which Deno does not support
3. What will be the output when running this Deno script?
import { readFileStr } from 'https://deno.land/std/fs/mod.ts';
const data = await readFileStr('./file.txt');
console.log(data.trim());
Assuming file.txt contains " Hello Deno \n".
medium
A. Error: readFileStr is not a function
B. Hello Deno
C. undefined
D. oneD olleH

Solution

  1. Step 1: Understand readFileStr usage

    The function readFileStr was deprecated and removed in recent versions of Deno std library. Using it will cause an error.
  2. Step 2: Analyze output

    Since readFileStr is not a function, the script will throw an error.
  3. Final Answer:

    Error: readFileStr is not a function -> Option A
  4. Quick Check:

    Function availability = D [OK]
Hint: Use Deno.readTextFile or Deno.readTextFileSync instead of deprecated readFileStr. [OK]
Common Mistakes:
  • Expecting original spaces without trim()
  • Confusing readFileStr with non-existent function
  • Ignoring await causing undefined
4. You migrated a Node.js script to Deno but get this error: PermissionDenied: read access to './data.json' is not allowed. How do you fix it?
medium
A. Install the missing npm package for file access.
B. Change the file path to an absolute path.
C. Run the script with deno run --allow-read flag.
D. Use require() instead of import.

Solution

  1. Step 1: Understand Deno's permission model

    Deno requires explicit permission flags to access files for security.
  2. Step 2: Apply correct permission flag

    Using --allow-read grants read access to files, fixing the error.
  3. Final Answer:

    Run the script with deno run --allow-read flag. -> Option C
  4. Quick Check:

    Permission error fix = A [OK]
Hint: Add --allow-read flag to grant file read permission. [OK]
Common Mistakes:
  • Ignoring permission flags in Deno
  • Trying to fix path instead of permissions
  • Using Node.js require() which Deno disallows
5. You have this Node.js code snippet using the 'fs' module:
const fs = require('fs');
const data = fs.readFileSync('./info.txt', 'utf8');
console.log(data);
How should you rewrite it in Deno to read the file synchronously?
hard
A. const data = Deno.readFile('./info.txt'); console.log(data);
B. const data = await Deno.readTextFile('./info.txt'); console.log(data);
C. import fs from 'https://deno.land/std/fs/mod.ts'; const data = fs.readFileSync('./info.txt');
D. const data = Deno.readTextFileSync('./info.txt'); console.log(data);

Solution

  1. Step 1: Identify synchronous file read in Deno

    Deno provides readTextFileSync() for synchronous text file reading.
  2. Step 2: Compare options

    const data = Deno.readTextFileSync('./info.txt'); console.log(data); correctly uses readTextFileSync and logs the data synchronously.
  3. Final Answer:

    const data = Deno.readTextFileSync('./info.txt'); console.log(data); -> Option D
  4. Quick Check:

    Synchronous file read in Deno = A [OK]
Hint: Use Deno.readTextFileSync for sync file reading like Node's readFileSync. [OK]
Common Mistakes:
  • Using await with synchronous functions
  • Trying to import Node.js fs module in Deno
  • Using readFile which returns Uint8Array, not string
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard