Babel-node not found - Heroku Deploy - node.js

I am trying to deploy a simple Ecommerce website that has Reactjs , Node, Express and MongoDB. I have followed a tutorial to deploy it to the heroku. I have used babel but in the tutorial, it wasn't used. I know we don't use babel for production and used only for the development purpose, but I am not sure how I would still deploy my website.
The server is working perfectly locally and also the Heroku build is successful. But when I visit my deployed app on heroku it says application error.
Here are the logs from Heroku:
2020-06-29T16:04:44.812179+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-29T16:04:48.072669+00:00 app[web.1]:
2020-06-29T16:04:48.072690+00:00 app[web.1]: > e-commerce-site#1.0.0 start /app
2020-06-29T16:04:48.072691+00:00 app[web.1]: > babel-node backend/server.js
2020-06-29T16:04:48.072691+00:00 app[web.1]:
2020-06-29T16:04:48.105827+00:00 app[web.1]: sh: 1: babel-node: not found
2020-06-29T16:04:48.110266+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-29T16:04:48.111030+00:00 app[web.1]: npm ERR! syscall spawn
2020-06-29T16:04:48.111915+00:00 app[web.1]: npm ERR! file sh
2020-06-29T16:04:48.112482+00:00 app[web.1]: npm ERR! errno ENOENT
2020-06-29T16:04:48.114018+00:00 app[web.1]: npm ERR! e-commerce-site#1.0.0 start: `babel-node backend/server.js`
2020-06-29T16:04:48.114155+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-06-29T16:04:48.114342+00:00 app[web.1]: npm ERR!
2020-06-29T16:04:48.114508+00:00 app[web.1]: npm ERR! Failed at the e-commerce-site#1.0.0 start script.
2020-06-29T16:04:48.114601+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-29T16:04:48.133545+00:00 app[web.1]:
2020-06-29T16:04:48.134148+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-29T16:04:48.134771+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-06-
29T16_04_48_124Z-debug.log
2020-06-29T16:04:48.213867+00:00 heroku[web.1]: Process exited with status 1
2020-06-29T16:04:48.265610+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-29T16:04:48.268292+00:00 heroku[web.1]: State changed from crashed to starting
2020-06-29T16:04:57.328678+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-29T16:05:00.299582+00:00 app[web.1]:
2020-06-29T16:05:00.299595+00:00 app[web.1]: > e-commerce-site#1.0.0 start /app
2020-06-29T16:05:00.299595+00:00 app[web.1]: > babel-node backend/server.js
2020-06-29T16:05:00.299596+00:00 app[web.1]:
2020-06-29T16:05:00.308802+00:00 app[web.1]: sh: 1: babel-node: not found
2020-06-29T16:05:00.312668+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-29T16:05:00.313206+00:00 app[web.1]: npm ERR! syscall spawn
2020-06-29T16:05:00.313637+00:00 app[web.1]: npm ERR! file sh
2020-06-29T16:05:00.314093+00:00 app[web.1]: npm ERR! errno ENOENT
2020-06-29T16:05:00.315953+00:00 app[web.1]: npm ERR! e-commerce-site#1.0.0 start: `babel-node backend/server.js`
2020-06-29T16:05:00.316283+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-06-29T16:05:00.316613+00:00 app[web.1]: npm ERR!
2020-06-29T16:05:00.316974+00:00 app[web.1]: npm ERR! Failed at the e-commerce-site#1.0.0 start script.
2020-06-29T16:05:00.317312+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-29T16:05:00.344371+00:00 app[web.1]:
2020-06-29T16:05:00.344828+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-29T16:05:00.345202+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-06-29T16_05_00_319Z-debug.log
2020-06-29T16:05:00.406294+00:00 heroku[web.1]: Process exited with status 1
2020-06-29T16:05:00.466244+00:00 heroku[web.1]: State changed from starting to crashed
File Name: Server.js
The file where I have all the connections for MongoDB:
import express from "express";
import data from "./data";
import dotenv from "dotenv";
import config from "./config";
import mongoose from "mongoose";
import userRoute from "./routes/userRoute";
import productRoute from "./routes/productRoute";
import bodyParser from "body-parser";
dotenv.config();
const mongodbUrl = config.MONGODB_URL;
const PORT = process.env.PORT || 5000;
mongoose.connect(mongodbUrl , {
useNewUrlParser : true,
useUnifiedTopology: true,
useCreateIndex: true
}).catch(error => console.log(error.reason));
const app = express();
app.use(bodyParser.json());
app.use("/api/users" , userRoute);
app.use("/api/products" , productRoute);
if (process.env.NODE_ENV === "production"){
app.use(express.static("./frontend/build"));
}
app.listen(PORT , console.log(`Server started at ${PORT}`));
File Name: config.js
export default{
MONGODB_URL: process.env.MONGODB_URL || "mongodb://localhost/ecommercesite",
JWT_SECRET: process.env.JWT_SECRET || "somethingsecret"
}
File Name: Package.json
{
"name": "e-commerce-site",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build" : "cd frontend && npm run build",
"install-client" : "cd frontend && npm install",
"heroku-postbuild" : "npm run install-client && npm run build",
"start": "babel-node backend/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.16"
},
"devDependencies": {
"#babel/cli": "^7.10.1",
"#babel/core": "^7.10.1",
"#babel/node": "^7.10.1",
"#babel/preset-env": "^7.10.1",
"nodemon": "^2.0.4"
}
}

Related

Hosting Discord Bot through Heroku, EADDRINUSE error repeating after trying previous suggestions

I'm trying to host a Discord bot for the first time through Heroku (also my first time using the site). It was running perfectly locally, but I started receiving errors in regards to the $PORT once I went online. When I looked that up, I saw I needed to listen to the server in order for the port to stick, but every attempt I've done results in the EADDRINUSE error. I've looked over and tried many examples through these previous answers here and here, deleted modules and reinstalled them countless times, ended node.exe processes before booting up, but I keep running into the error. I must be missing something but I can't figure it out and I feel like I'm just running in circles. Any help would be appreciated.
The error report:
2020-07-28T21:24:01.605923+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-28T21:24:03.399990+00:00 app[web.1]:
2020-07-28T21:24:03.400006+00:00 app[web.1]: > bot#1.0.0 start /app
2020-07-28T21:24:03.400006+00:00 app[web.1]: > node bot.js
2020-07-28T21:24:03.400006+00:00 app[web.1]:
2020-07-28T21:24:04.323323+00:00 app[web.1]: Ready!
2020-07-28T21:24:06.981374+00:00 app[web.1]: Listening on 50667
2020-07-28T21:24:07.141720+00:00 app[web.1]: events.js:292
2020-07-28T21:24:07.141721+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-07-28T21:24:07.141722+00:00 app[web.1]: ^
2020-07-28T21:24:07.141722+00:00 app[web.1]:
2020-07-28T21:24:07.141724+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::50667
2020-07-28T21:24:07.141725+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)
2020-07-28T21:24:07.141725+00:00 app[web.1]: at listenInCluster (net.js:1361:12)
2020-07-28T21:24:07.141726+00:00 app[web.1]: at Server.listen (net.js:1447:7)
2020-07-28T21:24:07.141727+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-07-28T21:24:07.141727+00:00 app[web.1]: at Client.<anonymous> (/app/bot.js:21075:4)
2020-07-28T21:24:07.141727+00:00 app[web.1]: at Client.emit (events.js:315:20)
2020-07-28T21:24:07.141743+00:00 app[web.1]: at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-07-28T21:24:07.141745+00:00 app[web.1]: at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-07-28T21:24:07.141752+00:00 app[web.1]: at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
2020-07-28T21:24:07.141752+00:00 app[web.1]: at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
2020-07-28T21:24:07.141753+00:00 app[web.1]: Emitted 'error' event on Server instance at:
2020-07-28T21:24:07.141753+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-07-28T21:24:07.141753+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-07-28T21:24:07.141754+00:00 app[web.1]: code: 'EADDRINUSE',
2020-07-28T21:24:07.141754+00:00 app[web.1]: errno: 'EADDRINUSE',
2020-07-28T21:24:07.141755+00:00 app[web.1]: syscall: 'listen',
2020-07-28T21:24:07.141755+00:00 app[web.1]: address: '::',
2020-07-28T21:24:07.141756+00:00 app[web.1]: port: 50667
2020-07-28T21:24:07.141756+00:00 app[web.1]: }
2020-07-28T21:24:07.154255+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-07-28T21:24:07.154464+00:00 app[web.1]: npm ERR! errno 1
2020-07-28T21:24:07.157313+00:00 app[web.1]: npm ERR! bot#1.0.0 start: `node bot.js`
2020-07-28T21:24:07.157445+00:00 app[web.1]: npm ERR! Exit status 1
2020-07-28T21:24:07.157646+00:00 app[web.1]: npm ERR!
2020-07-28T21:24:07.157759+00:00 app[web.1]: npm ERR! Failed at the bot#1.0.0 start script.
2020-07-28T21:24:07.157832+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-07-28T21:24:07.169750+00:00 app[web.1]:
2020-07-28T21:24:07.169882+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-07-28T21:24:07.169957+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-07-28T21_24_07_159Z-debug.log
2020-07-28T21:24:07.254000+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-28T21:24:07.225012+00:00 heroku[web.1]: Process exited with status 1
package.json
{
"name": "bot",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"discord.js": "^12.2.0",
"exit-hook": "^2.2.0",
"express": "^4.17.1",
"http": "0.0.1-security",
"webpack-dev-server": "^3.11.0"
},
"scripts": {
"start": "node bot.js",
"stop-win": "Taskkill /IM node.exe /F"
},
"main": "bot.js",
"devDependencies": {},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
Current code (though I have tried many different ones as well.)
const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;
express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index'))
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
},);
I understand that I should probably run the bot as a Worker instead of Web through Heroku, but the option is not available to me for some reason and my Procfile was doing nothing.
I know there must be something I'm overlooking. When I run the stop-win script, it kills two node.exe processes even when I try running the code only once.
I've been looking at this for too long (days!) and keep going in circles, I need some fresh eyes and ideas. Please help!
EDIT:
Thanks Tin Nguyen for pointing me in the right direction for the Procfile! I was able to use this thread to make an echo, and thus a functioning Procfile making it a worker. This let me fix all of the mess. Thank you very much!
I think the error is comming from the port! look at the errors,
Ready!
Listening on 50667
events.js:292
throw er; // Unhandled 'error' event
Error: listen EADDRINUSE: address already in use :::50667
it says "address already in use", try to change it and let me noticied if it works!

'npm start' in node.js doesn't works

node App.js works, but npm start doesn't works.
I just followed this nodejs tutorial (tutorial is written by Korean).
I tried to change code to:
"scripts": {
"start": "webpack-dev-server"
}
but it didn't work.
this is my code:
App.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
package.json
{
"name": "codlab-nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node js"
},
"author": "",
"license": "ISC"
}
package-lock.json
{
"name": "codlab-nodejs",
"version": "1.0.0",
"lockfileVersion": 1
}
This is the err msg.
C:\Users\김동희\codlab-nodejs>npm start
> codlab-nodejs#1.0.0 start C:\Users\김동희\codlab-nodejs
> node js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'C:\Users\김동희\codlab-nodejs\js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! codlab-nodejs#1.0.0 start: `node js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the codlab-nodejs#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\김동희\AppData\Roaming\npm-cache\_logs\2019-08-03T14_03_42_211Z-debug.log
In your package.json change the value of the property "start".
Replace:
"start": "node js"
With:
"start": "node App.js"
The start npm script is trying to run a file called js, which does not exist and consequently fails.
Instead, set your start npm script to be the correct command that asks Node.js to run your App.js file.
Your package.json would include something like this:
"scripts": {
"start": "node App.js"
}

Parse Server not recognizing APP_ID

I have installed Parse Server on Heroku and forked the Parse Server Example. When I git push heroku master I get the error
"You must provide an appIp!"
Error log:
019-03-20T11:03:56.517489+00:00 heroku[web.1]: Starting process with command `npm start`
2019-03-20T11:03:59.418738+00:00 app[web.1]:
2019-03-20T11:03:59.418754+00:00 app[web.1]: > parse-server-example#1.4.0 start /app
2019-03-20T11:03:59.418756+00:00 app[web.1]: > node index.js
2019-03-20T11:03:59.418757+00:00 app[web.1]:
2019-03-20T11:04:01.887096+00:00 heroku[web.1]: State changed from starting to crashed
2019-03-20T11:04:01.724008+00:00 app[web.1]:
2019-03-20T11:04:01.724030+00:00 app[web.1]: /app/node_modules/parse-server/lib/ParseServer.js:218
2019-03-20T11:04:01.724032+00:00 app[web.1]: throw err;
2019-03-20T11:04:01.724033+00:00 app[web.1]: ^
2019-03-20T11:04:01.724105+00:00 app[web.1]: You must provide an appId!
2019-03-20T11:04:01.779713+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-03-20T11:04:01.780520+00:00 app[web.1]: npm ERR! errno 7
2019-03-20T11:04:01.782955+00:00 app[web.1]: npm ERR! parse-server-example#1.4.0 start: `node index.js`
2019-03-20T11:04:01.783173+00:00 app[web.1]: npm ERR! Exit status 7
2019-03-20T11:04:01.783716+00:00 app[web.1]: npm ERR!
2019-03-20T11:04:01.783983+00:00 app[web.1]: npm ERR! Failed at the parse-server-example#1.4.0 start script.
2019-03-20T11:04:01.784194+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-03-20T11:04:01.804701+00:00 app[web.1]:
2019-03-20T11:04:01.805007+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-03-20T11:04:01.805196+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-03-20T11_04_01_786Z-debug.log
2019-03-20T11:04:01.866235+00:00 heroku[web.1]: Process exited with status 7
index.js:
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://key
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || 'myMasterKey',
serverURL: process.env.SERVER_URL || 'http://myApp.herokuapp.com/parse',
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
var server = ParseServer({
verifyUserEmails: true,
publicServerURL: 'myApp.herokuapp.com/parse',
appName: 'myAppName',
emailAdapter: {
module: 'parse-server-simple-mailgun-adapter',
options: {
fromAddress: 'parse#example.com',
domain: 'domainFromMailGun.mailgun.org',
apiKey: 'myAPIKey',
}
}
});
I have provided the appId in appId: process.env.APP_ID || 'myAppId', or am I missing something here? Does the appId have to provided elsewhere?
First of all, please invalidate those MongoDB credentials immediately. They are forever compromised, and you need to generate new ones. Editing them out of your question is not enough.
I'm not totally clear on what you're trying to do here, but you're actually instantiating two Parse servers. You do provide an appId for the first one (api), but not for the second (server).
You probably only need one Parse Server. If you do actually need two for some reason, each one will need an appId.

Hosting an express app on Heroku error with mongoose

I'm building a mean stack app with ionic 2 and I want to host it on Heroku. The app is finished and runs fine locally and I have it connected to a mLabs database. When I push the app to Heroku I am getting the following error in the logs.
2017-04-10T12:32:15.558949+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2017-04-10T12:32:15.558953+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-04-10T12:32:15.558954+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-10T12:32:15.558951+00:00 app[web.1]: at Function.Module._load (module.js:417:25)
2017-04-10T12:32:15.558952+00:00 app[web.1]: at require (internal/module.js:20:19)
2017-04-10T12:32:15.558952+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:4:16)
2017-04-10T12:32:15.558951+00:00 app[web.1]: at Module.require (module.js:497:17)
2017-04-10T12:32:15.558954+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-10T12:32:15.558955+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-10T12:32:15.558955+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-10T12:32:15.558950+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15)
2017-04-10T12:32:15.567486+00:00 app[web.1]:
2017-04-10T12:32:15.577504+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-04-10T12:32:15.577867+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-04-10T12:32:15.578113+00:00 app[web.1]: npm ERR! node v6.10.2
2017-04-10T12:32:15.578341+00:00 app[web.1]: npm ERR! npm v3.10.10
2017-04-10T12:32:15.578578+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-04-10T12:32:15.578785+00:00 app[web.1]: npm ERR! ionic-hello-world# start: `node server.js`
2017-04-10T12:32:15.578954+00:00 app[web.1]: npm ERR! Exit status 1
2017-04-10T12:32:15.579249+00:00 app[web.1]: npm ERR!
2017-04-10T12:32:15.579426+00:00 app[web.1]: npm ERR! Failed at the ionic-hello-world# start script 'node server.js'.
2017-04-10T12:32:15.579621+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-04-10T12:32:15.579920+00:00 app[web.1]: npm ERR! not with npm itself.
2017-04-10T12:32:15.579746+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
2017-04-10T12:32:15.580101+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-04-10T12:32:15.580265+00:00 app[web.1]: npm ERR! node server.js
2017-04-10T12:32:15.580757+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-04-10T12:32:15.580428+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-04-10T12:32:15.580601+00:00 app[web.1]: npm ERR! npm bugs ionic-hello-world
2017-04-10T12:32:15.580878+00:00 app[web.1]: npm ERR! npm owner ls ionic-hello-world
2017-04-10T12:32:15.580993+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-04-10T12:32:15.588769+00:00 app[web.1]:
2017-04-10T12:32:15.589345+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-04-10T12:32:15.589646+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-04-10T12:32:15.679397+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:32:15.680194+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T12:32:15.673049+00:00 heroku[web.1]: Process exited with status 1
2017-04-10T12:32:18.568796+00:00 heroku[web.1]: Starting process with command `npm start`
2017-04-10T12:32:21.743026+00:00 app[web.1]:
2017-04-10T12:32:21.743041+00:00 app[web.1]: > ionic-hello-world# start /app
2017-04-10T12:32:21.743042+00:00 app[web.1]: > node server.js
2017-04-10T12:32:21.743042+00:00 app[web.1]:
2017-04-10T12:32:22.058223+00:00 app[web.1]: module.js:471
2017-04-10T12:32:22.058237+00:00 app[web.1]: ^
2017-04-10T12:32:22.058236+00:00 app[web.1]: throw err;
2017-04-10T12:32:22.058239+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2017-04-10T12:32:22.058238+00:00 app[web.1]:
2017-04-10T12:32:22.058241+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15)
2017-04-10T12:32:22.058242+00:00 app[web.1]: at Function.Module._load (module.js:417:25)
2017-04-10T12:32:22.058242+00:00 app[web.1]: at Module.require (module.js:497:17)
2017-04-10T12:32:22.058243+00:00 app[web.1]: at require (internal/module.js:20:19)
2017-04-10T12:32:22.058243+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:4:16)
2017-04-10T12:32:22.058244+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-04-10T12:32:22.058245+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-10T12:32:22.058245+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-10T12:32:22.058246+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-10T12:32:22.058246+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-10T12:32:22.067921+00:00 app[web.1]:
2017-04-10T12:32:22.080492+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-04-10T12:32:22.080827+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-04-10T12:32:22.080991+00:00 app[web.1]: npm ERR! node v6.10.2
2017-04-10T12:32:22.081154+00:00 app[web.1]: npm ERR! npm v3.10.10
2017-04-10T12:32:22.081323+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-04-10T12:32:22.081657+00:00 app[web.1]: npm ERR! Exit status 1
2017-04-10T12:32:22.081825+00:00 app[web.1]: npm ERR!
2017-04-10T12:32:22.081993+00:00 app[web.1]: npm ERR! Failed at the ionic-hello-world# start script 'node server.js'.
2017-04-10T12:32:22.082162+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-04-10T12:32:22.081490+00:00 app[web.1]: npm ERR! ionic-hello-world# start: `node server.js`
2017-04-10T12:32:22.082332+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
2017-04-10T12:32:22.082335+00:00 app[web.1]: npm ERR! not with npm itself.
2017-04-10T12:32:22.082498+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-04-10T12:32:22.082666+00:00 app[web.1]: npm ERR! node server.js
2017-04-10T12:32:22.082832+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-04-10T12:32:22.083001+00:00 app[web.1]: npm ERR! npm bugs ionic-hello-world
2017-04-10T12:32:22.083168+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-04-10T12:32:22.083170+00:00 app[web.1]: npm ERR! npm owner ls ionic-hello-world
2017-04-10T12:32:22.083338+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-04-10T12:32:22.092234+00:00 app[web.1]:
2017-04-10T12:32:22.092236+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-04-10T12:32:22.092237+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-04-10T12:32:22.188511+00:00 heroku[web.1]: Process exited with status 1
2017-04-10T12:32:22.201942+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:32:50.415338+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dry-retreat-69141.herokuapp.com request_id=898a0974-f3eb-47b2-a7ca-77a37cf99131 fwd="193.1.57.4" dyno= connect= service= status=503 bytes= protocol=https
2017-04-10T12:35:00.000000+00:00 app[api]: Build started by user alanmurphy1995#gmail.com
2017-04-10T12:36:27.620672+00:00 app[api]: Release v6 created by user alanmurphy1995#gmail.com
2017-04-10T12:36:27.620672+00:00 app[api]: Deploy 9f02cb4 by user alanmurphy1995#gmail.com
2017-04-10T12:36:27.804049+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T12:36:27.782474+00:00 app[api]: Release v6 created by user alanmurphy1995#gmail.com
2017-04-10T12:35:00.000000+00:00 app[api]: Build succeeded
2017-04-10T12:36:33.381932+00:00 heroku[web.1]: Starting process with command `npm start`
2017-04-10T12:36:36.544686+00:00 app[web.1]:
2017-04-10T12:36:36.544709+00:00 app[web.1]: > ionic-hello-world# start /app
2017-04-10T12:36:36.544710+00:00 app[web.1]: > node server.js
2017-04-10T12:36:36.544711+00:00 app[web.1]:
2017-04-10T12:36:37.082619+00:00 app[web.1]: App listening on port 8080
2017-04-10T12:37:33.784488+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2017-04-10T12:37:33.760270+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-04-10T12:37:33.760270+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-04-10T12:37:33.878656+00:00 heroku[web.1]: Process exited with status 22
2017-04-10T12:37:33.889982+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:37:34.773926+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dry-retreat-69141.herokuapp.com request_id=6ba08c4e-a269-4530-b0db-192da56e2724 fwd="193.1.57.4" dyno= connect= service= status=503 bytes= protocol=https
For reference this is my server.js file
// Set up
var express = require('express');
var app = express(); // create our app w/ express
var mongoose = require('mongoose'); // mongoose for mongodb
var morgan = require('morgan'); // log requests to the console (express4)
var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
var cors = require('cors');
// Configuration
//mongoose.connect('mongodb://localhost/reviewking');
mongoose.connect('Connecting to mLabs here URI not included for security reasons');
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());
app.use(cors());
app.use(express.static("www")); // Our Ionic app build is in the www folder (kept up-to-date by the Ionic CLI using 'ionic serve')
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'DELETE, PUT');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Models
var Review = mongoose.model('Review', {
title: String,
description: String,
rating: Number
});
// Routes
// Get reviews
app.get('/api/reviews', function(req, res) {
console.log("fetching reviews");
// use mongoose to get all reviews in the database
Review.find(function(err, reviews) {
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err)
res.send(err)
res.json(reviews); // return all reviews in JSON format
});
});
// create review and send back all reviews after creation
app.post('/api/reviews', function(req, res) {
console.log("creating review");
// create a review, information comes from request from Ionic
Review.create({
title : req.body.title,
description : req.body.description,
rating: req.body.rating,
done : false
}, function(err, review) {
if (err)
res.send(err);
// get and return all the reviews after you create another
Review.find(function(err, reviews) {
if (err)
res.send(err)
res.json(reviews);
});
});
});
// delete a review
app.delete('/api/reviews/:review_id', function(req, res) {
Review.remove({
_id : req.params.review_id
}, function(err, review) {
});
});
// listen (start app with node server.js) ======================================
app.listen(8080);
console.log("App listening on port 8080");
And this is my package.json file.
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve",
"start": "node server.js"
},
"dependencies": {
"#angular/common": "2.2.1",
"#angular/compiler": "2.2.1",
"#angular/compiler-cli": "2.2.1",
"#angular/core": "2.2.1",
"#angular/forms": "2.2.1",
"#angular/http": "2.2.1",
"#angular/platform-browser": "2.2.1",
"#angular/platform-browser-dynamic": "2.2.1",
"#angular/platform-server": "2.2.1",
"#ionic/storage": "1.1.7",
"#types/cordova-plugin-network-information": "0.0.3",
"angularfire2": "^2.0.0-beta.6",
"firebase": "^3.3.0",
"ionic-angular": "2.1.0",
"ionic-native": "2.4.1",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"sw-toolbox": "3.4.0",
"zone.js": "0.6.26",
"#ionic/app-scripts": "1.1.3",
"typescript": "2.0.9",
"mongoose": "^4.6.2",
"body-parser": "^1.15.2",
"cors": "^2.8.0",
"del": "2.2.0",
"express": "^4.14.0",
"http": "0.0.0",
"method-override": "^2.3.6",
"morgan": "^1.7.0",
"superlogin": "^0.6.1"
},
"devDependencies": {
"#ionic/app-scripts": "1.1.3",
"typescript": "2.0.9",
"mongoose": "^4.6.2",
"body-parser": "^1.15.2",
"cors": "^2.8.0",
"del": "2.2.0",
"express": "^4.14.0",
"http": "0.0.0",
"method-override": "^2.3.6",
"morgan": "^1.7.0",
"superlogin": "^0.6.1"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "ReviewApp: An Ionic project"
}
Any help with this error or a solution around this so I can push a working app to Heroku would help greatly.
Removing mongoose from devDependencies should fix it.
Explanation: mongoose is listed twice in package.json - once in dependencies and once in devDependencies, which don't get installed by Heroku.
I also suggest you alphabetize those dependency lists so that this kind of issue is easier to catch in the future.

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

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 expected, but then it tries to run "npm start" which I did not specify in the package.json file. This command fails, I'm guessing because it is not a server application, and I can not see the actual application deployed in it's place on Heroku. My application can be found here: https://github.com/uzilan/sufusku
So - how do I get Heroku not to run the "npm start" command, and what should it run instead? After running grunt build, the application is available on the dist folder.
package.json:
{
"name": "sufusku",
"version": "0.0.1",
"description": "Sufusku - makes your annoying sudoku easier",
"repository": {
"type": "git",
"url": "git://github.com/uzilan/sufusku.git"
},
"license": "(MIT OR Apache-2.0)",
"dependencies": {
"bower": "^1.4.1",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "^0.13.0",
"grunt-contrib-htmlmin": "^0.4.0",
"grunt-contrib-uglify": "^0.9.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-ng-annotate": "^1.0.1",
"load-grunt-config": "^0.17.2",
"time-grunt": "^1.2.1"
},
"devDependencies": {},
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"postinstall": "./node_modules/bower/bin/bower install && grunt build"
}
}
Gruntfile.js:
module.exports = function (grunt) {
var appname = require('./package.json').name;
require('load-grunt-config')(grunt, {
data: {
dist: 'dist/' + appname,
app: 'src',
distscripts: 'dist/' + appname + '/scripts',
diststyles: 'dist/' + appname + '/styles',
disthtml: 'dist/' + appname,
disttest: 'dist/' + appname + '/test',
appstyles: 'src/css'
}
});
require('time-grunt')(grunt);
grunt.registerTask('build', ['clean:dist', 'ngAnnotate:application', 'uglify', 'htmlmin', 'cssmin', 'copy:serve', 'concat:components']);
grunt.registerTask('serve', ['build', 'connect:livereload', 'watch']);
grunt.registerTask('default', function () {
grunt.task.run(['build']);
});
};
Heroku log:
...
heroku[web.1]: Starting process with command `npm start`
app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
app[web.1]: npm ERR! Linux 3.13.0-57-generic
app[web.1]: npm ERR! npm v2.11.3
app[web.1]: npm ERR! missing script: start
app[web.1]: npm ERR! Please include the following file with any support request:
app[web.1]: npm ERR!
app[web.1]: npm ERR! node v0.12.7
app[web.1]:
app[web.1]: npm ERR! /app/npm-debug.log
app[web.1]: npm ERR! If you need help, you may report this error at:
app[web.1]:
app[web.1]: npm ERR! <https://github.com/npm/npm/issues>
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `npm start`
app[web.1]: npm ERR! Linux 3.13.0-57-generic
app[web.1]: npm ERR! node v0.12.7
app[web.1]:
app[web.1]: npm ERR! missing script: start
...
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
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);

Resources