简体   繁体   中英

Heroku node app not starting

I have created a very basic nodejs app which works locally. when i am pushing it to my heroku server, app is getting crashed with following error in log

var express = require("express");

var bodyParser = require("body-parser");

var app = express();
var port = process.env.PORT||3000;

app.use(bodyParser.urlencoded({extended:true}));

app.get('/',function(req,res){res.status(200).send('Hello World')});

app.use(function (err, req, res, next) {
  console.error(err.stack);
  res.status(400).send(err.message);
});

app.listen(port, function () {
  console.log('Slack bot listening on port ' + port);
});
 2016-01-05T19:39:14.346745+00:00 heroku[web.1]: Starting process with command `npm start` 2016-01-05T19:39:16.207970+00:00 app[web.1]: npm ERR! Linux 3.13.0-71-generic 2016-01-05T19:39:16.209056+00:00 app[web.1]: npm ERR! npm v3.3.12 2016-01-05T19:39:16.210546+00:00 app[web.1]: npm ERR! 2016-01-05T19:39:16.210779+00:00 app[web.1]: npm 

ERR! https://github.com/npm/npm/issues

package.json

{
  "name": "slackbot",
  "version": "1.0.0",
  "description": "Slack Hello World Bot",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/fffff/SlackBot.git"
  },
  "author": "Jasim Aboobacker",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/fffff/SlackBot/issues"
  },
  "homepage": "https://github.com/fffff/SlackBot#readme",
  "dependencies": {
    "body-parser": "^1.14.2",
    "express": "^4.13.3"
  }
}

Just follow these steps one by one and it should work nicely. Download and install node and npm from websites.

link node

link npm

rest of the commands are as below

sudo -i

Put root password if asked.

Now go to the project folder of your choice through cmd/terminal

 npm install -g express
 npm install -g express-generator
 express
 cd . && npm install
 SET DEBUG=<*folder name*>:* & npm start

Now in the folder type the following command to set up git local directory.

 git init
 git add .
 git commit -m "initial commits"

Then create an account in Heroku and follow the following steps.

 heroku create <application_name>
 git push heroku master

nb:you may be asked to give username and password for your heroku account during the process ;so proceed accordingly.

Now type the following to add a single web dyno

 heroku ps:scale web=1

Then

 heroku open

Cheers!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM