Installing Node.js
1. Downloading Node.js
To install Node.js, visit the official Node.js website at nodejs.org and download the installer suitable for your operating system.
2. Verifying Installation
Once Node.js is installed, you can verify the installation by opening a terminal or command prompt and running the following commands:
# Check Node.js version
node -v
# Check npm version (Node Package Manager)
npm -v
3. Running a Simple Node.js Script
To ensure everything works correctly, you can create a simple JavaScript file calledapp.js
and run it with Node.js. Here’s a basic example:
// app.js
console.log('Hello, Node.js!');
After saving the file, run the following command in your terminal to execute the script:
# Run the script
node app.js
If everything is set up correctly, you should see "Hello, Node.js!" printed in the terminal.