First Application in Node.js
0 114
If you're just starting with Node.js and wondering how to create your very first app, you're in the right place. Node.js makes it easy to build scalable and high-performance applications with JavaScript on the server side. In this guide, we’ll walk you through the steps of setting up and running your first simple application using Node.js.
What is Node.js?
Node.js is an open-source, cross-platform JavaScript runtime built on Chrome’s V8 engine. It allows developers to run JavaScript code outside the browser, enabling server-side scripting with ease. It’s fast, lightweight, and ideal for building real-time web apps, APIs, and backend services.
Prerequisites
Before we begin, make sure you have the following installed on your system:
- Node.js (which includes npm - Node Package Manager)
- A text editor like VS Code or Sublime Text
- Basic knowledge of JavaScript
Step 1: Installing Node.js
Go to the official Node.js website and download the latest stable version suitable for your OS. Once installed, open your terminal or command prompt and run:
node -v
This will show the installed Node.js version. You can also check npm with:
npm -v
Step 2: Create a Project Folder
Start by creating a new folder for your application. Open a terminal and type:
mkdir my-first-node-app
cd my-first-node-app
Step 3: Initialize a Node.js Project
Now, initialize your project using npm. This will create a package.json
file that manages your app’s metadata and dependencies.
npm init -y
The -y
flag automatically fills in the default values so you can skip the questionnaire for now.
Step 4: Write Your First Node.js Script
Create a new file called app.js
in your project folder and open it in your code editor. Add the following code:
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, Node.js World!');
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
This script creates a simple web server that responds with a message when accessed on port 3000.
Step 5: Run the Application
To run the app, go back to your terminal and type:
node app.js
If everything is set up correctly, you’ll see:
Server running at http://localhost:3000/
Open your browser and visit http://localhost:3000
— you should see "Hello, Node.js World!" displayed on the screen.
Conclusion
Congratulations! You've just built your first Node.js application. From here, you can explore more advanced topics such as using frameworks like Express.js, connecting to databases, creating APIs, and much more. Node.js opens the door to powerful backend development using JavaScript, so keep experimenting and building!
If you’re passionate about building a successful blogging website, check out this helpful guide at Coding Tag – How to Start a Successful Blog. It offers practical steps and expert tips to kickstart your blogging journey!
For dedicated UPSC exam preparation, we highly recommend visiting www.iasmania.com. It offers well-structured resources, current affairs, and subject-wise notes tailored specifically for aspirants. Start your journey today!

Share:
Comments
Waiting for your comments