9

I am working on this project locally https://github.com/misterGF/CoPilot but now that it is finished, I would like to push it to heroku. the problem is telling heroku to start the app.

In the heroku example, the demo server runs after picking up the info from Procfile with contains this data

web: node index.js

But in my vuejs project, there is no index.js that servers the content.

I only have the main entry point which is index.html and the procfile doesn't work with HTML.

2
  • Thanks for the git repo, I was looking for something like this. Commented Sep 17, 2017 at 14:20
  • 1
    @bhansa Another good one is Quasar. I actually moved from CoPilot to quasar last month and haven't regretted it. Commented Jan 4, 2018 at 10:25

3 Answers 3

8

You also need to define a small static server to serve your index.html file. A simple example setup would be with http-server:

npm install -S http-server

And your Procfile becomes:

web: http-server ./ -p $PORT
Sign up to request clarification or add additional context in comments.

5 Comments

Hmm, I tried your answer and I get ` 'http-server' is not recognized as an internal or external command,` Do you know what could be wrong?
Current answer could not solve the problem, so I a putting a bounty
Did you install http-server correctly? Does it show up under dependencies in your package.json file? Also, can you run the command http-server ./ -p 8080 locally on your own machine?
Yes, everything is installed correctly. I am getting error module semver not found... i can't tell what the issue is
Does it run locally? Could you also post your Node and npm versions? Also, maybe this npm issue is related github.com/npm/npm/issues/15558
3
+50

You need to update your package.json file to let heroku know about the packages, for example if you are using express to serve your files:

"scripts": {
   "postinstall": "npm install express"
 }
 // "start": "node server.js" (executing server.js) during start

server.js

var express = require('express')
var path = require('path')
var serveStatic = require('serve-static')

var app = express()
app.use(serveStatic(path.join(__dirname, 'dist')))

var port = process.env.PORT || 8000
app.listen(port)
console.log('server started ' + port)

Don't forget to build.

Look here to read more about build conf: Customizing build process - Heroku


You can also install the http-server globally like this if that is a option:

npm install -g http-server

and update the Procfile to add the configuration as mentioned in above answers.

Just to know:

  • npm install will install both "dependencies" and "devDependencies"
  • npm install --production will only install "dependencies"
  • npm install --dev will only install "devDependencies"

Comments

2

Using http-server. but the package is not installed globally, so you will have to use the full path to it like so:

web: ./node_modules/http-server/bin/http-server ./ -p $PORT

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.