What are the most effective techniques for combining Vue.JS and Node.js backends into a single Heroku container?

I came across an interesting blog post today that discusses a method for deploying React applications. The author begins with a Node project and then creates a React project within a subfolder, along with some proxy configuration.

About 10 days ago, I didn't have such a clever approach when working with Vue.

  1. I started by creating a Vue project.
  2. After building it for production, I added a package.json and a server.js file in the dist folder created by the Vue build process.
  3. The package.json includes these two lines:
    "postinstall": "npm install express"
    and "start": "node server.js".

As a result, Express listens on port 8081 internally (but is translated to ports 80/443 by Heroku), allowing communication between the Vue frontend and the Node backend. While it technically works, I find this solution somewhat messy and like desperate hacking.

The primary goal is to avoid using two separate Heroku instances for a small personal project that consists of both frontend and backend components.

If you have any suggestions for a cleaner approach, I would greatly appreciate it!

Answer №1

To streamline your workflow, consider setting up a vue-cli project

Simply create a subfolder within your express project and modify your script (in package.json) to:

npm run vueproject && npm run expressproject

This way, both projects will launch simultaneously.

Remember to :

  • Assign different ports for each project.

  • Install dependencies from the expressproject into the vueproject package.

  • Be aware that this method is not considered best practice.

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

Utilizing the "return" keyword in Javascript outside of function declarations

Exploring the Impact of Using the Return Keyword in JavaScript Scripts Beyond Functions in Browsers and Node.js Recently, I experimented with utilizing the return keyword in a Node.js script like so: #!/usr/bin/env node return 10; My initial assumption ...

Navigating Passport.js: uncovering ways to reach the user object post-authentication

Currently implementing Passport.js for user login using username and password, following the sample code from the Passport site. Here are the essential parts of the code I have so far: app.use(passport.initialize()); app.use(passport.session()); passport ...

Is it possible to define a 2-D array using the ref( ) function in VueJS?

I'm looking to dynamically create a 2-D array that allows the number of rows in the first dimension to increase when clicking on a designated button. <script setup> ... // When defining the table as follows: var tab=ref([]) // This function is e ...

Firebase Identity Platform Error: Invalid Refresh Token (auth/invalid-refresh-token)

Currently, I am in the process of enhancing an existing Firebase Auth project by transitioning to Identity Platform to take advantage of multi-tenancy features. During my testing phase on the local emulator, I encountered some challenges: Users are not a ...

Is it possible to establish communication between JAVA and Javascript using Sockets?

Recently, I developed a Java application that generates some data and saves it in a text file on my computer. Instead of saving this data in a text file, I am looking to send it via Socket. Here is an example: Java public static void main(String argv[] ...

Using Vue to showcase the result of a form submission on a separate page

Working with a <form> in the context of vue has been successful as I am able to send the form data to the server, receive a JSON response, and print it on the console. However, my current challenge involves displaying this JSON response on a differe ...

What is the best way to dissect emails using Haraka?

After delving into the haraka project (at ), I managed to successfully install it on my linux machine. Now, I'm interested in finding a comprehensive tutorial on parsing email meta headers and content body using haraka. Despite searching through their ...

Enhance the Vue.js performance by preloading components

After discovering the benefits of lazy loading components, I decided to start implementing it in my project. However, I encountered some issues when trying to prefetch the lazy loaded components and vue-router routes. Upon inspecting with Chrome DevTools, ...

Failure to give an error message occurred during a POST request on Parse.com and ExpressJS platform

I'm facing an issue where a POST request I send fails with error code 500 and there is nothing showing up in my server side error log. It seems like the cloud method may be missing. What's interesting is that the same POST request works fine wit ...

Is ExpressJS encountering issues with invalid set-cookie headers?

When utilizing the ExpressJS res.cookie function to include cookies in the header, I noticed that the concatenation used in the cookie function does not add a trailing semicolon. In examining the code in ExpressJS and Connect, I came across the following: ...

Optimizing your Vue.js/webpack setup: Best practices for transpiling ES6/ES7

When setting up my project, I opted for the comprehensive webpack template available on GitHub. Now I'm looking to incorporate ES7 features like async functions. I've read about using babel plugins and attempted the following: { test: /&bsol ...

Enhanced approach to building with React and Express

Quick Summary: How can I set up a project using React on the front-end and Express on the back-end with just one package.json and node_modules folder? When starting a project that combines a React front-end and an Express back-end, my desired structure is ...

Error: The function registerUser from require(...) is not defined

I am facing an issue where I am trying to import the registerUser function inside router.post within the same file that houses its exported function (registerUser). However, when attempting to use it outside of this module, I receive the following error: ...

Employing v-btn for navigating to a different route depending on whether a specific condition is satisfied

Is there a way to prevent this button from redirecting to the specified URL? I want to implement a validation check in my method, and if it fails, I need to stop this button from performing any action. Any suggestions or assistance would be highly apprec ...

I need help setting up a personalized SMTP server for sending notification emails using Node.js

I have a need to send notification emails from my application to any email address, such as a Gmail account. I have explored modules like smtp-server, smtp-connection, and emailjs. This is what I have implemented so far: var SMTPServer = require('sm ...

What is the fastest way to remove the node_modules directory?

Is there a quicker way to delete the node_modules folder on Windows Explorer? It seems to take forever whenever I try to remove it. ...

Securing your route with Mocha Chai testing

I am currently working with an Express server and utilizing passport-local for authentication. One of my protected routes looks like this: app.post("/api/test", connect.ensureLoggedIn("/"), (req, res) => { let test = new Test(req.body); test .save() ...

CORS blocked the HTTP request due to the absence of the Access-Control-Allow-Origin header, although the header is actually present

Recently, I encountered an issue while working on a project using Python with Flask. I had created a REST API and needed my Vue app to interact with it and fetch data. However, I kept receiving an error message stating "No 'Access-Control-Allow-Origin ...

Vue: identifying observed object datatype (differentiating arrays from objects)

I have a basic Vue instance set up like this: <html> <body> <div id="container"> <input type="text" id="container" placeholder="type something" v-model="value"> <p>{{ value }}</p> </div ...

How can one eliminate the white space surrounding the data that Vue is binding?

Working with Vue, I've noticed a gap on the screen following the data binding. Instead of using Vanilla JavaScript's trim() function, is there a way to remove leading and trailing whitespace? Let me provide you with the code for the data binding ...