DEV Community

Aniebiet Aaron
Aniebiet Aaron

Posted on

Day 1 of 10, "Introduction to Node.js."

Learning Resources:

  1. Official Node.js Website:

    • Node.js Official Website
    • The official website provides installation instructions, documentation, and a wealth of resources for getting started with Node.js.
  2. Node.js Beginner's Guide:

  3. Node.js Wikipedia Page:

Sample Code:

Here's a simple "Hello World" program in Node.js to get you started:

// hello.js

// Load the 'http' module to create an HTTP server.
const http = require('http');

// Configure the HTTP server to respond with "Hello, World!" to all requests.
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello, World!\n');
});

// Listen on port 3000, and IP address defaults to 127.0.0.1 (localhost).
const port = 3000;
server.listen(port, () => {
  console.log(`Server running at http://127.0.0.1:${port}/`);
});
Enter fullscreen mode Exit fullscreen mode

To run this code:

  1. Save it to a file named hello.js.
  2. Open your terminal or command prompt.
  3. Navigate to the directory where hello.js is located.
  4. Run the following command:
node hello.js
Enter fullscreen mode Exit fullscreen mode

You should see the message "Server running at http://127.0.0.1:3000/" in your terminal. This means your Node.js server is up and running. You can access it by opening a web browser and visiting http://127.0.0.1:3000/ or http://localhost:3000/.

Feel free to modify the code and experiment with different responses to learn more about Node.js's capabilities.

Remember, this is just a starting point. As you progress through these series, you'll explore more complex Node.js applications and gain a deeper understanding of its features.

Top comments (0)