Stopping Heroku from running npm start + what to run instead?

后端 未结 2 534
忘了有多久
忘了有多久 2020-12-17 06:00

Disclaimer: I\'m a node.js/grunt/bower newbie.

I have a node.js/grunt/bower application that I\'m trying to deploy on Heroku. Heroku builds the application as expect

相关标签:
2条回答
  • 2020-12-17 06:15

    Thanks for the answer. After trying the tutorial mentioned above and looking at the solutions in node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON] I ended up writing a server.js file which solved the problem. And it looks like this:

    var express = require('express');
    var app = express();
    
    app.get('/', function (req, res) {
        res.sendFile(__dirname + '/index.html');
    });
    
    app.get(/^(.+)$/, function (req, res) {
        res.sendFile(__dirname + req.params[0]);
    });
    
    var PORT = process.env.PORT || 3000;
    
    app.listen(PORT);
    
    0 讨论(0)
  • 2020-12-17 06:33

    npm start is the default web process run when no other process has been specified in a Procfile. Since you say you don't want a server (a web process), the first thing to do is to scale the default process to zero:

    heroku scale web=0
    

    Next, you'll want to tell Heroku what process you want to run instead of web by adding its process types to a file called Procfile. For instance, if your app starts with node foobar.js, you could create a Procfile that looks like:

    bot: node foobar.js
    

    Then scale the 'bot' process up to at least one:

    heroku scale bot=1
    

    Looking at your code above, even though you say it isn't a server-based application, it looks very much like a server-based application. How do you start your app locally? Whatever the answer that should probably go into the Procfile, which you can learn more about here:

    • https://devcenter.heroku.com/articles/procfile

    disclosure: I'm the Node.js platform owner at Heroku

    0 讨论(0)
提交回复
热议问题