Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda