Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Hosting single page Angular app on Heroku using Express

I'm new to Angular and am trying to host a little app I built on Heroku, and I'm understanding I'd need a webserver. I've heard of Express, but never used it before. If someone would point out what I need to add to my server.js file in order for me to be able to host it on Heroku; that'd be much appreciated! Also, if there are better, easier solutions out there that would allow my app to be hosted on Heroku, please let me know.

My file structure is as follows:

Project/

|-- components
    |-- project.controller.js
    |-- project.factory.js
|-- css
|   |-- style.css
|   |
|-- node_modules   
|
|-- scripts
|   |-- app.js
|
|
|-- index.html
|-- server.js
|-- package.json
|-- README

The very simple code from my app.js file in /scripts) is:

(function() {



"use strict";

  angular
    .module('project', ['ngMaterial', 'firebase'])
    .config(function($mdThemingProvider) {
      $mdThemingProvider.theme('default')
        .primaryPalette('teal')
        .warnPalette('deep-orange')
        .accentPalette('indigo');
    });

})();

And the code that I've got so far from my server.js file is:

var express = require('express');
var app = express();

// app.use(express.static(__dirname + '/public'));

app.get('/', function(req, res){
  res.redirect('/index.html');
});

var PORT = process.env.PORT || 8080;
app.listen(PORT);

I'm understanding things are missing. I'd greatly appreciate some help in figuring this out. Thanks in advance! I'll gladly share more code if that could help.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You should add start in the scripts section from package.json where you gonna start your server. If you don't use any task runner such as grunt or gulp you would use node command to start your server. For your package.json check example below.

package.json

{
    "name": "project",
    "version": "0.0.0",
    "description": "Project",
    "main": "index.js",
    "author": "userName",
    "license": "MIT",
    "scripts": {
        "start": "node ./server.js"
    },
    "dependencies": {
         "angular": "^1.6.1",
         "angular-animate": "^1.5.8",
         "angular-aria": "^1.5.8",
         "angular-material": "^0.11.4",
         "mdi": "^1.7.22",
         "express": "^4.15.0"
    }
}

Now you would test this though command prompt with command npm start in the context of the project. If server get starting then you would try to deploy your app to heroku.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!