Hello World AppJS
Hello World AppJS
This project
will have a few routes to demonstrate how to handle different HTTP requests.
Create a New Folder: Create a new folder for your project. You can name it anything
you like.
Initialize Node.js Project: Open a terminal in the project folder and run the
following command to initialize a new Node.js project. Follow the prompts to set up
your project.
npm init
Install Dependencies: We'll use the Express framework for this project. Run the
following command to install Express as a dependency:
// app.js
const express = require('express');
const app = express();
const PORT = 3000; // You can change this to any port you prefer
// Define routes
app.get('/', (req, res) => {
res.send('Hello, this is the homepage!');
});
In the terminal, run the following command to start your Node.js application:
node app.js
You should see the message "Server is running on port 3000". Open your web browser
and navigate to http://localhost:3000 to see the homepage. You can also visit
http://localhost:3000/about and http://localhost:3000/contact to see the other
routes.
Congratulations! You've just created a simple Node.js project with an Express web
server. This is just a basic example, but you can build upon it by adding more
routes, connecting to databases, integrating front-end frameworks, and more.