# Getting Started with Node.js: Creating Your First Application

### **Introduction**

In this tutorial, we'll guide you through creating a simple "Hello World" application using Node.js. Whether you're using Linux or Windows, this beginner-friendly tutorial will help you set up your environment and write your first lines of Node.js code.

### **Prerequisites**

Before we start, ensure you have Node.js installed on your system. You can download it from the official Node.js website (provide the link). To verify the installation, open your terminal or command prompt and run `node -v`.

### **Step 1: Setting Up Your Project**

1.  Create a new directory for your project: `mkdir hello-world-nodejs`.
    
2.  Navigate to the project directory:
    
    *   On Linux: `cd hello-world-nodejs`
        
    *   On Windows: `cd hello-world-nodejs`
        
3.  Initialize a new Node.js project: `npm init -y`.
    
4.  This command creates a `package.json` file, which contains project information and dependencies.
    

### **Step 2: Writing Your First Node.js Code**

1.  Create a new file named `app.js` in your project directory.
    
2.  Open `app.js` in your code editor.
    

### **Step 3: Building the "Hello World" Application**

Let's write a simple program that outputs "Hello, World!" to the console and saves it to a text file.

```javascript
// Import the built-in 'fs' module
const fs = require('fs');

// Define the message
const message = 'Hello, World!\n';

// Write the message to a file named 'output.txt'
fs.writeFileSync('output.txt', message);

// Print the message to the console
console.log(message);
```

### **Step 4: Running Your Application**

1.  Save the changes you made to `app.js`.
    
2.  Open your terminal or command prompt and navigate to your project directory:
    
    *   On Linux: `cd path/to/your/project`
        
    *   On Windows: `cd path\to\your\project`
        
3.  Run the application: `node app.js`.
    

### **Conclusion**

Congratulations! You've successfully created your first Node.js application that prints "Hello, World!" to both the console and a text file. This tutorial introduced you to setting up a Node.js project, writing code, and running your application. Stay tuned for more advanced Node.js concepts in upcoming blogs.

### **Next Steps**

In the next blog, we'll explore asynchronous programming in Node.js and learn about handling callbacks and Promises.

### **Additional Resources**

*   Official Node.js documentation: [\[link\]](https://nodejs.org/en/docs)
