What is the best way to deploy Next.js and Node.js on Heroku without utilizing npm run build for the client side?

Hello, I have a dilemma with my Next.js project. If I build it, the connection to the backend breaks, which is not ideal. When I try to launch on Heroku using npm run build, everything works fine except for the backend connectivity issue...

Below is an excerpt from my package.json:

{
  ...
  "scripts": {
    "f": "next dev",
    "backend": "cd backend && npm run s --prefix backend",
    "build": "next build",
    "start": "next start",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix backend && npm run build"
  },
  ...
  ...
  "engines": {
    "node": "14.x",
    "npm": "7.16.0"
}

In my project structure, I have the following setup:

Next.js project > backend folder > backend files

Removing "npm run build" from the heroku-postbuild scripts causes the website to stop displaying the client side and instead shows an error message prompting me to check the logs...

I've hosted many websites on an Nginx VPS running Node.js projects successfully in the past, but for this particular site, I didn't want to incur the VPS fees hence trying to deploy on Heroku.

Do you think there's a workaround to address this issue?

Some relevant details:

  • I'm using a Mac
  • Installed Heroku via brew in the terminal
  • Ran buildpacks for Heroku/Node.js
  • Followed Git instructions accurately
  • The port for my backend is set to 5001
  • Attempting to access the website-url:5001/graphql results in an error... and yes, I have updated all URLs accordingly

Answer №1

Consider utilizing Docker by exposing separate ports for backend and frontend functionalities. An efficient approach is to incorporate Nginx running on a Linux image.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered an issue while trying to launch Next.js project

Error - Unable to locate module: 'C:\Users\User\Desktop\React Projektiudemy\app\next demo\first-next\node_modules\next\dist\compiled\regenerator-runtime\runtime.js' in 'C:&bsol ...

The input form in my Node.js project is not adapting to different screen sizes. I am currently utilizing ejs as the template

I have integrated ejs as a template in my Node.js project, but I am encountering an issue with the input form in the following code snippet. The form is unresponsive, preventing me from entering text or clicking on any buttons. What could be causing this ...

Integrating individual front end JavaScript files into an Express.js application

I've been working on a JavaScript file that contains over 200 lines of code for the front end logic of my project. It handles interactions like button clicks, image displays, and more, similar to a game. However, I'm struggling to figure out how ...

Struggling to fetch a refresh token in Express.js for a React and Node.js application

I am having trouble accessing a cookie that I previously set. During the login process, I returned a refresh token as an httpOnly cookie. const payload = {name, email}; console.log("payload: ", payload); const accessToken = jsonwebtoken.sign(pay ...

When using `useSWR`, it will return { null, null } for a successful request

When attempting to query the Firebase real-time database using useSWR in my next.js project, I encounter a perplexing issue where both the data and error variables always return as null. import useSWR from 'swr'; const LastSales: NextPage = () = ...

The deletion process simply adds a question mark to the existing URL and does not actually remove the blogpost

I've been working on a small blog application using Node and Express. Strangely, when trying to delete a blog post, clicking the submit button adds a "?" into the link as shown here: http://prntscr.com/gizmvu After thoroughly reviewing my code, I&apo ...

Node.js console and endpoint are returning an object, but the JSON object cannot be fetched

Currently, I am working on a project for an online course where I am utilizing an NLP sentiment analysis API. Although I have made significant progress, I seem to be stuck at the final step. When I send the URL for analysis via the API call, I can see the ...

The Tailwind Typography plugin simply maintains the default font size of heading tags without altering their style

I've been working on parsing an MDX file and converting it into React components. My tech stack includes TailwindCSS, Next.js, and React. Following the Tailwind documentation, I have installed the tailwind/typography plugin. In my tailwind.config.js ...

Tips for concealing JavaScript files from the Chrome Developer Tools while using Next.js

Currently working on a project using Next.js. I've noticed that the utils/components are quite visible through the Chrome Developer Tools, as shown in this image: Is there a way to hide them from being easily accessible? And most importantly, is it s ...

Searching for specific data within an embedded documents array in MongoDB using ID

While working with mongodb and nodejs to search for data within an embedded document, I encountered a strange issue. The query functions as expected in the database but not when implemented in the actual nodejs code. Below is the structure of my data obje ...

Tips for updating the version number in a non-integer JSON format

Every time I run this code, I want it to update the JSON file. The problem: 1. The version in the JSON file is stored as a string rather than an integer Solution: I plan to extract the version number, convert it to an integer by removing the periods, ...

Issue encountered: Inability to implement asynchronous functionality within a forEach loop while making an API request

When making a GET API call, the code looks like this router.get('/review', async (req, res) => { try { const entity = await Entity.find(); const entityId = []; Object.keys(entity).forEach((key) => { entityId.push(entity[ ...

The local strategy in PassportJS seems to be inactive

I am currently working on a node.js application that utilizes passportjs for authentication. However, I am encountering an issue where the login is not triggering the local strategy as expected. Despite following examples closely, I am unable to resolve t ...

Tips for uploading a file in LimeSurvey

Recently, I have been utilizing the Limesurvey API to develop a survey mobile application. One issue that I have encountered is that while I am able to successfully use all APIs, I consistently face difficulties when attempting to upload a file as it alway ...

unable to transmit information to server using axios

After collecting data from a form and attempting to send it to a Node.js server using Axios upon clicking the submit button, I am encountering issues. Despite my efforts, I cannot seem to successfully transfer the data. Strangely, I am not even receiving ...

Having trouble getting `npm start` to work for the Lite-server?

As a newcomer to Angular and web programming, I attempted to replicate the quickstart project on github/angular by using "npm start" to initiate lite-server. However, following a tutorial [link] (https://www.youtube.com/watch?v=-zW1zHqsdyc&t=804s), I ...

Vercel prevents Google from including website in search results

After deploying my Next.js app on Vercel, I encountered an issue where Google's crawl requests were returning a 401 unauthorized error. This problem is also evident in the deployment logs console as indicated below: Even though I added the URL to the ...

Can you provide me with the URL for the jQuery post function?

Could someone please clarify which URL I should use in the $.post call to the server for a node.js file? Most tutorials demonstrate with PHP files, but I'm unsure about calling node.js files. Should I post it to the app.js file or the route file? Thi ...

Setting up bcrypt on an Ubuntu EC2 instance

gyp ERR! encountered a build error gyp ERR! the command `make` failed with exit code: 2 gyp ERR! details: g... gyp ERR! additional system information: Linux version 3.2.0-40-virtual gyp ERR! specified command: "node" "/usr/local/lib/node_modules/npm/node_ ...

What is the best way to extract specific data from a CSV file and incorporate it into a JSON object using csvparser?

I'm relatively new to nodejs and am working on a project where I need to extract data from a CSV file containing COVID information for various countries and US states. My goal is to filter out only the US states from this data and display it in a tabl ...