Homework & Coding Practice
Homework/Practice Coding Assignment (20-min)
Part 1: Set Up a Simple Node.js Project Directory Structure
Steps:
Create a new directory:
bash코드 복사mkdir my-node-project cd my-node-projectInitialize a new
package.jsonfile:bash코드 복사npm init -yAdd a script to
package.json:json코드 복사{ "name": "my-node-project", "version": "1.0.0", "scripts": { "start": "node index.js" } }Create an
index.jsfile:javascript코드 복사console.log('Welcome to My Node.js Project');Run the project:
bash코드 복사npm start
Part 2: Write and Save a Short Script Using REPL
Steps:
Open the REPL:
bash코드 복사nodeWrite and test the following:
javascript코드 복사// Define a multiplication function function multiply(a, b) { return a * b; } // Call the function multiply(3, 7);Save the commands to a file
script.js:javascript코드 복사const multiply = (a, b) => a * b; console.log('3 x 7 =', multiply(3, 7));Exit the REPL and run the script:
bash코드 복사node script.jsVerify the output.
Expected Outcomes
Students successfully set up a Node.js environment and understand how to manage versions with
nvm.They gain hands-on experience with the REPL and basic scripting.
Homework reinforces project initialization and debugging concepts.
Last updated