Getting Started with Node.js: Installation and Your First Program
Node.js has become a powerhouse in web development, allowing developers to use JavaScript for server-side scripting. In this blog post, we’ll guide you through the process of installing Node.js and creating your first program. Let’s embark on this exciting journey!
Installing Node.js:
Step 1: Update Package List
Before installing Node.js, it’s a good practice to update your package list:
sudo apt-get update
Step 2: Install Node.js
Now, install Node.js using the package manager:
sudo apt-get install nodejs
Step 3: Install npm (Node Package Manager)
npm is the package manager for Node.js. Install it with:
sudo apt-get install npm
To verify successful installation, check the versions:
node -v
npm -v
Your First Node.js Program:
Now that Node.js is installed, let’s create a simple “Hello, Node.js!” program.
Step 1: Create a Project Folder
Navigate to your desired directory and create a new folder for your project:
mkdir myNodeProject
cd myNodeProject
Step 2: Create a JavaScript File
Using your favorite text editor (like VSCode, Sublime Text, or Nano), create a file named app.js
:
// app.js
console.log("Hello, Node.js!");
Step 3: Run Your Program
Execute your Node.js program:
node app.js
You should see the output:
Hello, Node.js!
Congratulations! You’ve just run your first Node.js program.
Conclusion:
Node.js opens up a world of possibilities for server-side JavaScript development. With a straightforward installation process and a simple “Hello, Node.js!” program, you’ve taken your first steps into this exciting ecosystem. You can explore frameworks like Express.js, interact with databases, and build scalable web applications.
Happy coding!