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

前提是你 提交于 2019-11-30 15:42:40

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:

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

uzilan

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!