0% found this document useful (0 votes)
6 views1 page

Hello World AppJS

This document outlines the steps to create a basic Node.js project using the Express framework, including setting up the project, installing dependencies, and creating an Express app with defined routes. It provides instructions on how to initialize the project, create an app.js file with routes for homepage, about, and contact pages, and how to run the application. The document encourages further development by suggesting the addition of more routes and integrations with databases and front-end frameworks.

Uploaded by

m536
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Hello World AppJS

This document outlines the steps to create a basic Node.js project using the Express framework, including setting up the project, installing dependencies, and creating an Express app with defined routes. It provides instructions on how to initialize the project, create an app.js file with routes for homepage, about, and contact pages, and how to run the application. The document encourages further development by suggesting the addition of more routes and integrations with databases and front-end frameworks.

Uploaded by

m536
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Basic project that includes a web server using the Express framework.

This project
will have a few routes to demonstrate how to handle different HTTP requests.

Step 1: Set Up Your Project

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:

npm install express


Step 2: Create Your Express App

Create a file named app.js in your project folder.

// 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!');
});

app.get('/about', (req, res) => {


res.send('This is the about page.');
});

app.get('/contact', (req, res) => {


res.send('Contact us at [email protected].');
});

// Start the server


app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

Step 3: Run Your Application

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.

You might also like