Deploying the Backend on Heroku
Learn how to deploy a Node.js back-end server on Heroku.
In this lesson, we’ll deploy our back-end server to the web.
import express from 'express' import cors from 'cors' import movies from './api/movies.route.js' const app = express() app.use(cors()) app.use(express.json()) app.use("/api/v1/movies", movies) app.use('*', (req,res)=>{ res.status(404).json({error: "not found"}) }) export default app
We’ll be deploying our Node.js backend to Heroku’s servers, which will host and run the backend on the internet. The backend will connect to our MongoDB Atlas database in the cloud. The deployment process is relatively straightforward, and we can simply follow along with the instructions in the documentation to deploy Node.js applications on Heroku’s servers, as shown below:
Note: You need to purchase a Heroku subscription before executing the commands in this lesson that enable deployment.
First, we need a Heroku account. Go ahead and sign up if you don’t have an account already. Next, we need to install the Heroku Command Line Interface (CLI) to create and manage our Express applications on Heroku, as shown below:
When the installation completes, we can start using the Heroku command in the terminal. Type heroku login -i
, and this will prompt the user to enter their account details, as shown below:
If the ...