Learn how to set up a Node.js environment from scratch and create a simple server to kickstart your backend development journey.
Install Node.js and npm
- Download and install Node.js from the official website (https://nodejs.org/)
- Verify installation by running
node -vandnpm -vin your terminal
Set Up Your Project Folder
- Create a new directory for your project
- Navigate into the folder using the terminal
Initialize a New Node.js Project
- Run
npm init -yto create apackage.jsonfile with default settings
Create Your First Server File
- Create a file named
server.js(orapp.js) - Import the built-in
httpmodule usingconst http = require('http');
Write Basic Server Code
- Use
http.createServer()to create a server instance - Define a callback function to handle incoming requests and send responses
- Example: respond with “Hello, World!” to every request
Start the Server
- Use
server.listen(port, callback)to start the server on a specified port (e.g., 3000) - Log a message to the console confirming the server is running
Test Your Server
- Open a web browser or use a tool like Postman to visit
http://localhost:3000 - Verify that your “Hello, World!” message appears
Next Steps
- Learn to handle different routes and HTTP methods (GET, POST, etc.)
- Explore using frameworks like Express.js for easier server development
- Connect your server to databases and build APIs

