Heroku - Launch your code in development or live environments

I am currently hosting my express API on Heroku with two separate projects set up: one for my Master Branch (Prod) and the other for my Development branch (Dev).

Inside my package.json file, I have defined two scripts:

  "scripts": {
    "devStart": "export NODE_ENV=development && nodemon server.js",
    "start": "export NODE_ENV=production && node server.js"
  }

I am looking for a way to automatically run the "DevStart" script on the Development branch and the "start" script on the Master branch. Currently, the production environment is running smoothly with the node start default script.

While I am aware that I can use a procfile to specify commands, I am hesitant as both Dev and Prod branches share the same codebase, requiring me to manually update the procfile with each commit. Is there a more dynamic solution to handle this configuration?

Answer №1

Alright, so maybe this isn't the most conventional way, but here's how I tackled it.

I discovered that I could set the NODE_ENV variable for the Heroku app using the terminal:

heroku config:set NODE_ENV=development --app {app-name}

However, my package JSON was overriding this setting upon deployment.

  "scripts": {
    "devStart": "export NODE_ENV=development && nodemon server.js",
    "start": "export NODE_ENV=production && node server.js"
  },

So, I made the following adjustment:

  "scripts": {
    "localStart": "export NODE_ENV=development && nodemon server.js",
    "start": "node server.js"
  },

This successfully resolved the issue, eliminating the need for a Procfile or configuring environment variables within Heroku.

Within Heroku, I have two separate apps: one for production, where I leave the NODE_ENV variable as default (production), and another for development, where I specifically set the NODE_ENV variable to 'development'.

Each app is linked to a distinct branch within the same codebase (Development for the Development app and Master for the Production app). Deploying to either branch triggers a rebuild using the appropriate NODE_ENV variable for that specific branch.

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

Design a dynamic top navigation bar in Angular or any other framework that automatically adjusts to the size of the screen, similar to the responsive bookmarks bar in

Could you offer guidance or suggestions on how to design a navigation bar (using Angular 1, jQuery, CSS, etc) that emulates the functionality of Google Chrome bookmarks bar when resizing the page? Essentially, as the page size decreases, a new button/symbo ...

Convert your Airbnb short link into the full link

I am currently developing an application that utilizes Airbnb links as part of its input. So far, I have identified two types of links: Long form, for example: . These are commonly used on desktop. Short form, such as: . These shorter links are often shar ...

Embed API allows users to showcase a variety of charts all on one page

I am trying to incorporate two google analytics timeline charts using the embed API on a single page. However, I am facing an issue where only one chart is appearing. The first chart should display bounce rate data and the second chart should display sessi ...

What is the best way to input keys into the currently selected element?

During my experimentation, I discovered that several modals and dropdowns in my tests open with their input boxes automatically focused. I found a way to verify if an element is in focus, but I'm wondering if there's a quicker method to input ke ...

Prerender is running independently of the dynamic page title and meta tags rendering process

As part of a POC, I was integrating prerender.io with an angular-node application for SEO purposes. My application can be found HERE. The good news is that all three links are being crawled successfully, as confirmed by receiving a 200 OK status for all li ...

What is the best method to deliver static html assets to a node server that is being operated with nginx?

I am currently running a server using pm2 and nginx to serve up my React app. My goal is to have the server only respond to requests sent by the client, but when I try to access jwcuisine.io, I receive a "CANNOT GET /" message. I attempted to configure th ...

Unable to expand or collapse rows in ng-table

Looking to implement an expand and collapse feature for ng-table, where clicking on a row should expand it to show more detail. However, currently all rows expand on click. Any ideas on how to achieve this? Any assistance would be greatly appreciated, tha ...

Establish a connection to an SSH server using Node.js code, specifying the SSH key and server hostname for

Having VPN access allows me to SSH into the server using the following command in the terminal: ssh qa-trinath01.my-qa This command works perfectly fine when executed from the terminal. However, when attempting to connect via Node.js, I encounter issues ...

Coordinate the timing of CSS animation with the loading of the page

Despite the abundance of similar questions, none have quite addressed my specific query. I've created a preloader using CSS animation and I want it to synchronize perfectly with the page load. While I can trigger the animation on page load, I'm s ...

Tips for ensuring a controller function only runs once in AngularJS

I have a controller that is being referenced in some HTML. The HTML changes on certain events, causing the controller function code to execute multiple times. The issue lies in a portion of the code that should only be executed once. Shown below is the ...

Using PHP and jQuery to generate push notifications can result in issues with server performance

To simulate push notifications using PHP, I have implemented the following method: An AJAX call is made to a server-side script using jQuery. The script includes a for loop with a sleep function after each iteration to introduce delay. If a certain condi ...

Implementing Jquery Datatables in C# Codebase

I'm struggling to populate my jQuery Datatable with a List. Currently, I am writing the list to a file and accessing it in my view-model. Is this the correct approach? This is the snippet of my code: List<string> list = new List<string> ...

How can I import a JavaScript file from the assets folder in Nuxt.js?

I have explored multiple methods for importing the JS file, but I am still unable to locate it. Can anyone guide me on how to import a JS file from the assets folder to nuxt.config.js and have it accessible throughout the entire website? nuxt.config.js he ...

Display an AJAX div when the image is hovered over and have it track the movement of

I am seeking assistance with my website project, which involves providing users with download links to movies. However, I am struggling to make the preview_block div(id) appear when the mouse hovers over the movie_block div(id). Additionally, I am having ...

Using Socket.io with Node.js

Currently, I am incorporating socket.io within a NodeJS application. The socket.io page can be accessed at localhost:8081/socket.io/. However, my goal is to have it located at localhost:8081/hola/socket.io/. Is this achievable? var express = require("e ...

Express session not persisting properly after deployment on both Heroku and Netlify platforms

I recently deployed my React frontend to Netlify and my Express backend to Heroku, both using session management. While the session functionality works perfectly locally, it does not seem to work after deployment. Upon checking the database, I can see th ...

using variables as identifiers in nested JSON objects

Within my code, there is a JSON object named arrayToSubmit. Below is the provided snippet: location = "Johannesburg, South Africa"; type = "bench"; qty = 1; assetNumber = 15; arrayToSubmit = { location : { type : { 'qty' ...

Trigger animation once you've scrolled past a designated point in the document

I created a count-up counter animation using JavaScript, but the issue is that the counter starts animating as soon as I refresh the page regardless of where I am on the page or if the counter is even visible. I would like the counter to only start workin ...

Guide to displaying a loading image when selecting an item from a dropdown menu using JavaScript

When using three drop-down lists and performing an AJAX call on each dropdown list's onclick function, I encountered a delay in loading the data. To address this issue, I attempted to display a loading image while processing the AJAX call. <form ...

Conceal HTML elements from the bottom as new content is being added dynamically

I am currently working on a comments feed feature. By default, only the first four comments are displayed, with an option to show more when clicking the "show more" anchor. The issue I'm facing is that if new comments are dynamically added, the CSS hi ...