Learn how to construct a specialized folder arrangement and include TypeScript within an Express server before launching it on the Heroku platform

Creating and deploying my MEAN app on Heroku has been a breeze so far. The front end is up and running smoothly on the provided website, but I'm stuck when it comes to compiling and building the server part of my app, especially since it's in TypeScript and follows a certain folder structure like this - myCodeStructure where the src folder is Angular CLI generated.

I've searched online and read through resources like https://devcenter.heroku.com/articles/mean-apps-restful-api, but they all seem to focus on simple server.js files with NPM start using node server.js.

Can anyone guide me through how to transpile my server code to JavaScript, build it properly, and then run it on Heroku?

Answer №2

Responded by Drenai in a remark:

Prior to deploying an Express server with TypeScript, it's recommended that you first create and run a basic example project using Express and TypeScript. One notable missing component is the absence of a Procfile in your setup. Refer to existing examples like this one found at github.com/bergergit/mean-typescript-starter. Setting up an Express build on Heroku can encounter various issues if not executed properly, so starting with a functional example project will provide a solid foundation.

Answer №3

If you want to deploy a web app on Heroku, follow these steps:

  1. Start by setting up an express server.
  2. Build your Angular app using the command ng build.
  3. In the express server, point the public folder to
    path.join(__dirname, '../client/dist/project)
    . This will serve the dist files generated when building the Angular app via express. Accessing http://localhost:3000 while the express app is running at port 3000 will display content from this dist folder.
  4. Transfer the dist folder from the Angular project to the public folder in the express project.
  5. Change the npm start command to node ..
  6. Use the Heroku CLI to deploy the app.

These steps will enable you to serve static files through express. https://expressjs.com/en/starter/static-files.htm

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

There seems to be an issue with loading Angular2 (error)

I am not sure what the error is, as I have not made any changes to my code and everything was working fine before. The compiler is successfully compiling. I am using Angular CLI. The page is not displaying and only shows "Loading...". In the console I see ...

Create an interface that inherits from another in MUI

My custom interface for designing themes includes various properties such as colors, border radius, navbar settings, and typography styles. interface ThemeBase { colors: { [key: string]: Color; }; borderRadius: { base: string; mobile: st ...

Utilize Angular to transform items in a nested array into comma-delimited values prior to assigning them to a grid

Here is an excerpt from a JSON response retrieved from an API: { "totalCount": 2, "customAttributes": [ { "objectType": "OWNER", "atrributeId" ...

The property 'i' is not recognized on the type 'AppComponent'

Check out my code here; Take a look at my code here I attempted to implement a delete button to remove array objects using the ngFor directive ...

Could someone assist me in identifying the issue with this logfile and guiding me in the correct direction?

Can someone help me troubleshoot the ng e2e issue in my code? Here's a screenshot of the log file: https://i.sstatic.net/PCrab.png I apologize for the formatting of the package.json file. `package.json` file: { "name": "planning", "version": "0. ...

Tips for detecting the end of a scroll view in a list view

I've encountered an issue with my scrollView that allows for infinite scrolling until the banner or container disappears. What I'm aiming for is to restrict scrolling once you reach the last section, like number 3, to prevent the name part from m ...

Finding the selected text in an Angular TypeScript select box

Is there a way to retrieve the text of the selected option using the onchange function in Angular with TypeScript? ...

What steps should I take to address this issue using IONIC and TypeScript?

Running into an issue with my TypeScript code for an Ionic project. I'm attempting to pass the value of the variable (this.currentroom) from the getCurrentRoom() function to another function (getUser()) but it's not working. Here's my chat s ...

Tips for integrating Less and Bootstrap in an Angular 6 project

After making changes to angular.json to use less as the styleext, I tested it by creating a component. However, now I want to incorporate Bootstrap classes into my component's css/less. I specifically want all buttons in my component to have the .mx-1 ...

Guide to constructing ODM models in Node.js for utilization with nedb

Currently in search of an ODM module compatible with Nedb in NodeJs-Express. Wondering if there is a way to utilize Mongoose or Waterline schemas alongside nedb for validation purposes, even though there is no official adapter provided by Mongoose and Wate ...

Preventing form submission in Express.js and NodeJS: A step-by-step guide

I am currently using express-validator to validate my form. If there are any errors, I want to know the best way to prevent the form from being submitted and redirect back to the login page. The code I have now works, but I'm looking for a more effici ...

Using Node and Express to navigate to a URL within a React application

My goal is to open a user-provided URL in a reactjs application using node.js and express. I am incorporating material-ui and axios. Below is the code for the UI: This is a Proof of Concept for a UX testing project where the URL of the application to be ...

Is there a way to retrieve an HTML file from a different directory using Express?

I am currently utilizing an HTML file in the same folder. How can I access an HTML file saved in a different folder using express? Thank you. const express=require('express') const path=require('path') const app=express() app.get(& ...

Generating fresh objects to establish a Many-to-Many connection with Sequelize

I am currently utilizing NodeJS, Express, Sequelize, and PostgreSQL in my project. Within my application, I have defined two models: a "User" model and a "Social" model. My goal is to establish a many-to-many relationship where a user can be associated wi ...

After completing its tasks, Gulp closes down

How can I achieve live reload functionality with an express server using gulp? Every time I run gulp, it exits and I'm unable to access the server. The command line output is as follows: D:\Users\workspace\server>gulp server [11:31 ...

Integrating the frontend (HTML, CSS, and JavaScript) with the backend (Express server)

I've been trying to figure out the best way to connect the frontend and backend of a website, but I can't seem to find any clear answers online. Let's say you have a backend API with an endpoint that deletes a user's account when req ...

NodeJs encountered an issue due to the absence of defined username and data

I am facing an issue while trying to open the places.ejs file by clicking the submit button on the show.js page. Similar to how the show.ejs page opens upon clicking the submit button on the new.ejs file, I am encountering a reference error. Any assistance ...

While the Angular application in VS Code may be successfully compiled, the most recent changes may not appear in the browser

Lately, while working on my angular application using Visual Studio Code as my code editor, I encountered two unexpected issues that have been causing me trouble. After running the command ng serve in the terminal, I receive a √ Compiled successfully. ...

Error encountered while attempting to load SWC binary for win32/ia32 in a Next JS application

Upon installing a Next.js app using the command npx create-next-app@latest, I encountered an error while running the app. Can anyone explain why this error occurred and provide a solution? PS D:\New folder\my-app> npm run dev [email pr ...

Error with JavaScript callback functions

After creating a POST route, I encountered unexpected behavior in the code below. The message variable does not display the expected output. app.post("/", function (req, res, error) { var message = ""; tableSvc.createTable("tableName", function (error ...