📅  最后修改于: 2023-12-03 15:06:15.785000             🧑  作者: Mango
Heroku is a cloud platform that enables developers to deploy, manage, and scale web applications. In this tutorial, we will learn how to deploy a Javascript web application to Heroku.
Before we start, make sure you have the following installed on your system:
mkdir my-app
cd my-app
npm
.npm init -y
npm install express body-parser --save
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
app.get('/', (req, res) => {
res.send('Hello World!');
});
Procfile
in your project directory and add the following line:web: node index.js
git init
git add .
git commit -m "Initial commit"
heroku login
heroku create your-app-name
git push heroku master
heroku open
Congratulations! You have successfully deployed a Javascript web application to Heroku using the Heroku CLI.
In this tutorial, we learned how to deploy a Javascript web application to Heroku using the Heroku CLI. We installed the necessary dependencies, created an index.js file, set up a Procfile, initialized a git repository, and pushed our changes to Heroku. The Heroku platform provides a simple and powerful solution for deploying, managing, and scaling web applications.