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.
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.