Bird
Raised Fist0
Typescriptprogramming~20 mins

Running TypeScript with ts-node - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ts-node Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output when running this TypeScript code with ts-node?

Consider the following TypeScript code snippet. What will be printed to the console when you run it using ts-node?

Typescript
const greet = (name: string): string => {
  return `Hello, ${name}!`;
};

console.log(greet("Alice"));
AHello, Alice!
Bgreet is not defined
CHello, undefined!
DSyntaxError: Unexpected token
Attempts:
2 left
💡 Hint

Think about how arrow functions and template strings work in TypeScript and JavaScript.

🧠 Conceptual
intermediate
1:30remaining
Which command runs a TypeScript file directly using ts-node?

You want to run a TypeScript file named app.ts without compiling it first. Which command should you use?

Anpm run app.ts
Bnode app.ts
Ctsc app.ts && node app.js
Dts-node app.ts
Attempts:
2 left
💡 Hint

Remember, ts-node runs TypeScript files directly without manual compilation.

🔧 Debug
advanced
2:30remaining
What error occurs when running this code with ts-node?

Look at this TypeScript code. When run with ts-node, what error will it produce?

Typescript
function add(a: number, b: number): number {
  return a + b;
}

console.log(add(5, "3"));
ASyntaxError: Unexpected string
BArgument of type 'string' is not assignable to parameter of type 'number'
CNo error, output is 8
DTypeError: Cannot add number and string
Attempts:
2 left
💡 Hint

Think about TypeScript's type checking during execution with ts-node.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error when run with ts-node?

Identify which code snippet will cause a syntax error when executed with ts-node.

A
const z: string = 'hello
console.log(z);
B
const x: number = 10;
console.log(x);
C
function foo() { return 42; }
console.log(foo());
D
let y = 5
console.log(y);
Attempts:
2 left
💡 Hint

Look carefully at string literals and missing characters.

🚀 Application
expert
3:00remaining
How many items are in the resulting array after running this code with ts-node?

Consider this TypeScript code run with ts-node. How many elements does the result array contain?

Typescript
const numbers = [1, 2, 3, 4, 5];
const result = numbers.map(n => {
  if (n % 2 === 0) {
    return n * 2;
  }
});
console.log(result);
A0
B3
C5
D2
Attempts:
2 left
💡 Hint

Remember how map works and what happens when a function returns undefined.

Practice

(1/5)
1. What is the main purpose of using ts-node when working with TypeScript?
easy
A. To debug JavaScript code in the browser
B. To compile TypeScript files into JavaScript files only
C. To convert JavaScript files into TypeScript files
D. To run TypeScript files directly without compiling them first

Solution

  1. Step 1: Understand what ts-node does

    ts-node allows running TypeScript files directly without a separate compilation step.
  2. Step 2: Compare options

    The other options describe unrelated tasks like compiling only, converting JS to TS, or debugging JS.
  3. Final Answer:

    To run TypeScript files directly without compiling them first -> Option D
  4. Quick Check:

    ts-node runs TS files directly = A [OK]
Hint: Remember ts-node skips manual compile step [OK]
Common Mistakes:
  • Thinking ts-node only compiles without running
  • Confusing ts-node with JavaScript debuggers
  • Assuming ts-node converts JS to TS
2. Which of the following is the correct command to run a TypeScript file named app.ts using ts-node?
easy
A. ts-node app.ts
B. ts-node app.js
C. node app.ts
D. tsc app.ts

Solution

  1. Step 1: Identify the correct file extension for ts-node

    ts-node runs TypeScript files, so the file must have a .ts extension.
  2. Step 2: Check the commands

    ts-node app.ts uses ts-node with the correct .ts file. ts-node app.js uses .js file which is incorrect. node app.ts uses node which cannot run .ts files directly. tsc app.ts runs the compiler but does not execute.
  3. Final Answer:

    ts-node app.ts -> Option A
  4. Quick Check:

    Run ts-node with .ts file = A [OK]
Hint: Use ts-node with .ts files, not .js [OK]
Common Mistakes:
  • Trying to run .js files with ts-node
  • Using node to run .ts files directly
  • Confusing tsc (compiler) with ts-node (runner)
3. What will be the output when running the following TypeScript code with ts-node?
const greet = (name: string) => `Hello, ${name}!`;
console.log(greet("Alice"));
medium
A. undefined
B. Hello, Alice!
C. SyntaxError
D. greet is not defined

Solution

  1. Step 1: Understand the code behavior

    The function greet takes a string and returns a greeting message using template literals.
  2. Step 2: Predict the console output

    Calling greet("Alice") returns "Hello, Alice!" which is logged to the console.
  3. Final Answer:

    Hello, Alice! -> Option B
  4. Quick Check:

    Function returns greeting string = D [OK]
Hint: Template literals print variables inside strings [OK]
Common Mistakes:
  • Expecting a syntax error due to arrow function
  • Confusing output with function definition
  • Missing the console.log output
4. You try to run ts-node script.ts but get an error: Cannot find module 'typescript'. What is the most likely fix?
medium
A. Run node script.ts instead
B. Rename script.ts to script.js
C. Install TypeScript using npm install typescript
D. Delete node_modules folder

Solution

  1. Step 1: Understand the error message

    The error says TypeScript module is missing, which ts-node needs to run TS files.
  2. Step 2: Fix by installing TypeScript

    Installing TypeScript with npm adds the required module so ts-node can work.
  3. Final Answer:

    Install TypeScript using npm install typescript -> Option C
  4. Quick Check:

    Missing module error = install TypeScript [OK]
Hint: Missing module? Run npm install typescript [OK]
Common Mistakes:
  • Trying to run node on .ts files directly
  • Renaming files without fixing dependencies
  • Deleting node_modules without reinstalling
5. You want to run a TypeScript file server.ts with ts-node and enable source maps for better debugging. Which command should you use?
hard
A. ts-node --enable-source-maps server.ts
B. ts-node --source-map server.ts
C. ts-node --debug server.ts
D. ts-node --map-source server.ts

Solution

  1. Step 1: Identify the correct option for source maps

    The official ts-node option to enable source maps is --enable-source-maps.
  2. Step 2: Check other options

    The other options are incorrect or invalid flags for ts-node.
  3. Final Answer:

    ts-node --enable-source-maps server.ts -> Option A
  4. Quick Check:

    Enable source maps flag = --enable-source-maps [OK]
Hint: Use --enable-source-maps to debug TS with ts-node [OK]
Common Mistakes:
  • Using incorrect or non-existent flags
  • Confusing debug flag with source maps
  • Omitting the flag and missing debugging info
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