expressjsHow do I set up a project using Express.js and GitHub?
-
Create a repository on GitHub:
- Go to GitHub and log in with your credentials.
- Click on the plus icon in the top right corner and select New repository.
- Enter the repository name and click Create repository.
-
Clone the repository to your local machine:
- Copy the repository URL from the GitHub page.
- Open the terminal and navigate to the folder where you want to clone the repository.
- Enter
git clone <repository-url>
and press enter.
-
Initialize a new Node.js project:
- Navigate to the repository folder.
- Enter
npm init
and press enter. - Follow the instructions to create a
package.json
file.
-
Install Express.js:
- Enter
npm install express --save
and press enter. - This will install Express.js and add it to the
package.json
file.
- Enter
-
Create an
app.js
file and add the following code:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000, () => {
console.log('Server is listening on port 3000');
});
- This will create an Express.js server that listens on port 3000 and responds with
Hello World!
when the root URL is accessed.
-
Start the server:
- Enter
node app.js
and press enter. - This will start the Express.js server.
- Enter
-
Access the server:
- Open your browser and go to
http://localhost:3000
- You should see the
Hello World!
message.
- Open your browser and go to
Helpful links
More of Expressjs
- How do I set up a YAML configuration file for a Node.js Express application?
- How can I use express-zip js to zip and download files?
- How do I download a zip file using Express.js?
- How do I implement CSRF protection in an Express.js application?
- How can I disable the X-Powered-By header in Express.js?
- How can I use Express.js and Nest.js together to create a web application?
- How can I use Express.js to prevent XSS attacks?
- How do I use adm-zip with Express.js?
- How do I set the time zone in Express.js?
- How do I use Express.js to parse YAML files?
See more codes...