I have deployed a simple Nodejs app to Heroku and I keep getting an error in the application logs saying that the module "mongoose" cannot be found. I even provided a relative path instead of just saying require("mongoose"). The deployment succeeds and installs all the dependencies. The source code can be found here https://github.com/collinkleest/trim-io.
Here is the error log from heroku.
2020-10-17T02:01:42.000000+00:00 app[api]: Build started by user collinkleest#gmail.com
2020-10-17T02:01:59.000000+00:00 app[api]: Build succeeded
2020-10-17T02:01:59.493929+00:00 app[api]: Deploy af985be5 by user collinkleest#gmail.com
2020-10-17T02:01:59.493929+00:00 app[api]: Release v14 created by user collinkleest#gmail.com
2020-10-17T02:01:59.652847+00:00 heroku[web.1]: State changed from crashed to starting
2020-10-17T02:02:01.917601+00:00 heroku[web.1]: Starting process with command `npm start`
2020-10-17T02:02:04.175589+00:00 app[web.1]:
2020-10-17T02:02:04.175612+00:00 app[web.1]: > trim-io#0.0.1 start /app
2020-10-17T02:02:04.175612+00:00 app[web.1]: > node server.js
2020-10-17T02:02:04.175613+00:00 app[web.1]:
2020-10-17T02:02:04.369536+00:00 app[web.1]: internal/modules/cjs/loader.js:834
2020-10-17T02:02:04.369538+00:00 app[web.1]: throw err;
2020-10-17T02:02:04.369539+00:00 app[web.1]: ^
2020-10-17T02:02:04.369539+00:00 app[web.1]:
2020-10-17T02:02:04.369539+00:00 app[web.1]: Error: Cannot find module '../node_modules/mongoose'
2020-10-17T02:02:04.369540+00:00 app[web.1]: Require stack:
2020-10-17T02:02:04.369540+00:00 app[web.1]: - /app/models/urlEntity.js
2020-10-17T02:02:04.369541+00:00 app[web.1]: - /app/server.js
2020-10-17T02:02:04.369541+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
2020-10-17T02:02:04.369542+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:687:27)
2020-10-17T02:02:04.369542+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:903:19)
2020-10-17T02:02:04.369543+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-10-17T02:02:04.369543+00:00 app[web.1]: at Object.<anonymous> (/app/models/urlEntity.js:1:18)
2020-10-17T02:02:04.369543+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-10-17T02:02:04.369544+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-10-17T02:02:04.369544+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-10-17T02:02:04.369545+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-10-17T02:02:04.369545+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:903:19) {
2020-10-17T02:02:04.369545+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-10-17T02:02:04.369546+00:00 app[web.1]: requireStack: [ '/app/models/urlEntity.js', '/app/server.js' ]
2020-10-17T02:02:04.369546+00:00 app[web.1]: }
2020-10-17T02:02:04.389361+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-10-17T02:02:04.389827+00:00 app[web.1]: npm ERR! errno 1
2020-10-17T02:02:04.398788+00:00 app[web.1]: npm ERR! trim-io#0.0.1 start: `node server.js`
2020-10-17T02:02:04.399025+00:00 app[web.1]: npm ERR! Exit status 1
2020-10-17T02:02:04.399280+00:00 app[web.1]: npm ERR!
2020-10-17T02:02:04.399493+00:00 app[web.1]: npm ERR! Failed at the trim-io#0.0.1 start script.
2020-10-17T02:02:04.399722+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-10-17T02:02:04.420468+00:00 app[web.1]:
2020-10-17T02:02:04.420707+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-10-17T02:02:04.420857+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-10-17T02_02_04_400Z-debug.log
2020-10-17T02:02:04.487055+00:00 heroku[web.1]: Process exited with status 1
2020-10-17T02:02:04.554273+00:00 heroku[web.1]: State changed from starting to crashed
Here is my server.js for reference as well:
const express = require("express");
const UrlEntity = require("./models/urlEntity");
const mongoose = require("./node_modules/mongoose");
const urlEntity = require("./models/urlEntity");
const app = express();
require('dotenv').config();
const mongoUri = "mongodb+srv://" + process.env.MONGO_USR + ":" + process.env.MONGO_PASS + "#" + process.env.MONGO_URL + "/" + process.env.MONGO_DB + "?retryWrites=true&w=majority";
mongoose.connect(
mongoUri,
{ useNewUrlParser: true, useUnifiedTopology: true}
);
app.use(express.json());
app.use(express.static('public'));
async function checkIdExists(id){
let exists = await UrlEntity.exists({uniqueId: id});
return exists;
}
function generateId(){
let randomId = Math.random().toString(20).substr(2, 8);
while(!(checkIdExists(randomId))){
randomId = Math.random().toString(20).substr(2, 8);
}
return randomId;
}
// redirect functionality
app.get("/:id", async (req, res) => {
if (req.params.id !== null || req.params.id !== undefined){
let doc = await UrlEntity.findOne({uniqueId: req.params.id});
res.redirect(doc.targetUrl);
} else {
res.redirect('/');
}
});
// create new url
app.post("/create-url", async (req, res) => {
console.log("in post");
let id = generateId();
await UrlEntity.create({uniqueId: id,
targetUrl: req.body.url,
dateCreated: req.body.date});
res.send(`${req.protocol}://${req.get('host')}/${id}`);
});
app.listen(process.env.PORT || 5000, () => {console.log("Trim.io API Started")});
You put mongoose in your devDependencies, which will be removed at runtime. (Link from your code) You need to move it to dependencies so that it will be available at runtime.
try changing the const mongoose = require("./node_modules/mongoose")
back to const mongoose = require("mongoose");
Don't forget to set your environment variables MONGO_USR, MONGO_PASS e.t.c on heroku settings. Your server will not start if the environment variable is not set.
Lastly I advice you use a connection string like this mongodb+srv://user:password#cluster2.bftwu.mongodb.net/databaseName
without concatenating
Related
I am trying to deploy my code on heroku and it give me Error.
Provide me the solution.
It show unexpected token ... which i cannot resolve.
i am using mongo atlas online database link to connect to database.
For more clearity i am adding my git repository
github.com/laxitnahar/temp
ERROR:-
2022-08-05T11:57:48.831721+00:00 heroku[web.1]: State changed from crashed to starting
2022-08-05T11:57:51.114009+00:00 heroku[web.1]: Starting process with command `npm start`
2022-08-05T11:57:52.585567+00:00 app[web.1]:
2022-08-05T11:57:52.585595+00:00 app[web.1]: > backend#1.0.0 start /app
2022-08-05T11:57:52.585596+00:00 app[web.1]: > node server.js
2022-08-05T11:57:52.585596+00:00 app[web.1]:
2022-08-05T11:57:52.809406+00:00 app[web.1]: /app/node_modules/connect-mongo/build/main/lib/MongoStore.js:75
2022-08-05T11:57:52.809420+00:00 app[web.1]: constructor({ collectionName = 'sessions', ttl = 1209600, mongoOptions = {}, autoRemove = 'native', autoRemoveInterval = 10, touchAfter = 0, stringify = true, crypto, ...required }) {
2022-08-05T11:57:52.809423+00:00 app[web.1]: ^^^
2022-08-05T11:57:52.809423+00:00 app[web.1]: SyntaxError: Unexpected token ...
2022-08-05T11:57:52.809423+00:00 app[web.1]: at createScript (vm.js:56:10)
2022-08-05T11:57:52.809423+00:00 app[web.1]: at Object.runInThisContext (vm.js:97:10)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at Module._compile (module.js:542:28)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at Module.load (module.js:487:32)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2022-08-05T11:57:52.809425+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2022-08-05T11:57:52.809425+00:00 app[web.1]: at Module.require (module.js:497:17)
2022-08-05T11:57:52.809425+00:00 app[web.1]: at require (internal/module.js:20:19)
2022-08-05T11:57:52.815363+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/connect-mongo/build/main/index.js:5:38)
2022-08-05T11:57:52.822611+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-08-05T11:57:52.822966+00:00 app[web.1]: npm ERR! errno 1
2022-08-05T11:57:52.826142+00:00 app[web.1]: npm ERR! backend#1.0.0 start: `node server.js`
2022-08-05T11:57:52.826182+00:00 app[web.1]: npm ERR! Exit status 1
2022-08-05T11:57:52.826329+00:00 app[web.1]: npm ERR!
2022-08-05T11:57:52.826388+00:00 app[web.1]: npm ERR! Failed at the backend#1.0.0 start script.
2022-08-05T11:57:52.826457+00:00 app[web.1]: npm ERR! This is probably not a problem with npm```
MongoStore.js
```class MongoStore extends session.Store {
constructor({ collectionName = 'sessions', ttl = 1209600, mongoOptions = {}, autoRemove = 'native', autoRemoveInterval = 10, touchAfter = 0, stringify = true, crypto, ...required }) {
super();
this.crypto = null;
debug('create MongoStore instance');
const options = {
collectionName,
ttl,
mongoOptions,
autoRemove,
autoRemoveInterval,
touchAfter,
stringify,
crypto: {
...{
secret: false,
algorithm: 'aes-256-gcm',
hashing: 'sha512',
encodeas: 'base64',
key_size: 32,
iv_size: 16,
at_size: 16,
},
...crypto,
},
...required,
};```
I think It's because you forgot to write two curly brackets } at the end of your program.
This kind of errors usually happens when you forgot to write a bracket or curly brackets.
I'm developing an API in node.js that's deployed to heroku, that uses a custom module to fetch weather information from another API.
Here is the App Tree
Here is my app.js
const data_lluvias = require('./data_lluvias');
...
app.post('/aguas_lluvia', (req, res) => {
let data = data_lluvias.getDataLluvias;
res.json(data);
});
app.listen(port, () => {
console.log('Server running');
});
This is the weather module
const url = 'https://climatologia.meteochile.gob.cl/application/productos/boletinClimatologicoDiario';
const getDataLluvias = async () => {
const response = await fetch(url, {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
const data = response.json();
return data;
};
module.exports = {
getDataLluvias
};
I can't get heroku to find the module that is in the same folder that my app.js file
Here's the console log
2022-07-16T02:56:32.844556+00:00 heroku[web.1]: State changed from crashed to starting
2022-07-16T02:56:34.518501+00:00 heroku[web.1]: Starting process with command `npm start`
2022-07-16T02:56:36.166569+00:00 app[web.1]:
2022-07-16T02:56:36.166608+00:00 app[web.1]: > conectamilk-npurin#1.0.0 start
2022-07-16T02:56:36.166610+00:00 app[web.1]: > node app.js
2022-07-16T02:56:36.166610+00:00 app[web.1]:
2022-07-16T02:56:36.324024+00:00 app[web.1]: node:internal/modules/cjs/loader:936
2022-07-16T02:56:36.324025+00:00 app[web.1]: throw err;
2022-07-16T02:56:36.324026+00:00 app[web.1]: ^
2022-07-16T02:56:36.324026+00:00 app[web.1]:
2022-07-16T02:56:36.324026+00:00 app[web.1]: Error: Cannot find module './data_lluvias'
2022-07-16T02:56:36.324027+00:00 app[web.1]: Require stack:
2022-07-16T02:56:36.324027+00:00 app[web.1]: - /app/app.js
2022-07-16T02:56:36.324042+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-07-16T02:56:36.324044+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-07-16T02:56:36.324044+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-07-16T02:56:36.324044+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-07-16T02:56:36.324045+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:6:22)
2022-07-16T02:56:36.324045+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-07-16T02:56:36.324045+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-07-16T02:56:36.324046+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-07-16T02:56:36.324046+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-07-16T02:56:36.324046+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
2022-07-16T02:56:36.324047+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-07-16T02:56:36.324047+00:00 app[web.1]: requireStack: [ '/app/app.js' ]
2022-07-16T02:56:36.324047+00:00 app[web.1]: }
2022-07-16T02:56:36.449409+00:00 heroku[web.1]: Process exited with status 1
2022-07-16T02:56:36.545505+00:00 heroku[web.1]: State changed from starting to crashed
2022-07-16T02:56:36.550346+00:00 heroku[web.1]: State changed from crashed to starting
I've been trying different paths in the require but none worked.
Can anyone point me the right direction please?
Thanks
When we try to deploy our nodejs app in heroku that show us this problem !
by the way I have large app that content a lot of routes. I are not knew if can deploy it with this way I have litter confuse.
//package.json
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/ww"
},
for runing Heroku : npm start
2021-10-17T19:17:50.244905+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2021-10-17T19:17:50.244906+00:00 app[web.1]: Require stack:
2021-10-17T19:17:50.244906+00:00 app[web.1]: - /app/routes/users.js
2021-10-17T19:17:50.244906+00:00 app[web.1]: - /app/routes/index.js
2021-10-17T19:17:50.244907+00:00 app[web.1]: - /app/app.js
2021-10-17T19:17:50.244907+00:00 app[web.1]: - /app/bin/www
2021-10-17T19:17:50.244907+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
2021-10-17T19:17:50.244908+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27)
2021-10-17T19:17:50.244908+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-10-17T19:17:50.244909+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-10-17T19:17:50.244909+00:00 app[web.1]: at Object.<anonymous> (/app/routes/users.js:10:16)
2021-10-17T19:17:50.244909+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-10-17T19:17:50.244910+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-17T19:17:50.244910+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-10-17T19:17:50.244910+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-10-17T19:17:50.244911+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19) {
2021-10-17T19:17:50.244911+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-10-17T19:17:50.244911+00:00 app[web.1]: requireStack: [
2021-10-17T19:17:50.244911+00:00 app[web.1]: '/app/routes/users.js',
2021-10-17T19:17:50.244912+00:00 app[web.1]: '/app/routes/index.js',
2021-10-17T19:17:50.244912+00:00 app[web.1]: '/app/app.js',
2021-10-17T19:17:50.244912+00:00 app[web.1]: '/app/bin/www'
2021-10-17T19:17:50.244913+00:00 app[web.1]: ]
2021-10-17T19:17:50.244913+00:00 app[web.1]: }
2021-10-17T19:17:50.261989+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-17T19:17:50.262348+00:00 app[web.1]: npm ERR! errno 1
2021-10-17T19:17:50.269748+00:00 app[web.1]: npm ERR! project-work#0.0.0 start: `node ./bin/www`
2021-10-17T19:17:50.269860+00:00 app[web.1]: npm ERR! Exit status 1
2021-10-17T19:17:50.269999+00:00 app[web.1]: npm ERR!
2021-10-17T19:17:50.270110+00:00 app[web.1]: npm ERR! Failed at the project-work#0.0.0 start script.
2021-10-17T19:17:50.270230+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-17T19:17:50.274000+00:00 app[web.1]:
2021-10-17T19:17:50.274070+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-17T19:17:50.274112+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-17T19_17_50_270Z-debug.log
2021-10-17T19:17:50.422905+00:00 heroku[web.1]: Process exited with status 1
2021-10-17T19:17:50.494116+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-17T19:17:50.498518+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-17T19:17:52.375838+00:00 heroku[web.1]: Starting process with command `
I am deploying a fullstack react/express app to Heroku, it has managed to deploy. There are multiple errors in the Heroku logs which I have cannot seem to understand/figure out. I also have a Procfile with web: node server.js
I have tried to clear cache - delete node_modules and package.json then npm install again but this has not made a difference.
Heroku Logs
2020-11-15T13:08:12.713935+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:08:12.713935+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:08:12.713935+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:08:12.783289+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:08:12.818062+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:08:12.826070+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:08:21.448256+00:00 heroku[web.1]: Starting process with command `node server.js`
2020-11-15T13:08:24.324135+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:08:24.324170+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:08:24.324175+00:00 app[web.1]: ^
2020-11-15T13:08:24.324175+00:00 app[web.1]:
2020-11-15T13:08:24.324180+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:08:24.324185+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:08:24.324185+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:08:24.324190+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:08:24.324190+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:08:24.324190+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:08:24.324192+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:08:24.324196+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:08:24.418110+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:08:24.454083+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:23:24.786742+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-journey-43421.herokuapp.com request_id=aa6c54d3-cfe3-4f74-b4c5-93018f00ba97 fwd="84.9.66.95" dyno= connect= service= status=503 bytes= protocol=https
2020-11-15T13:23:26.240301+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-journey-43421.herokuapp.com request_id=ec07ad1c-091f-4e53-b50d-9632b66dd2d4 fwd="84.9.66.95" dyno= connect= service= status=503 bytes= protocol=https
2020-11-15T13:27:28.000000+00:00 app[api]: Build started by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.458958+00:00 app[api]: Deploy 12d81f3b by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.458958+00:00 app[api]: Release v12 created by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.625747+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:29:09.000000+00:00 app[api]: Build succeeded
2020-11-15T13:29:17.927953+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-15T13:29:20.083139+00:00 app[web.1]:
2020-11-15T13:29:20.083155+00:00 app[web.1]: > movie-database#1.0.0 start /app
2020-11-15T13:29:20.083155+00:00 app[web.1]: > node server.js
2020-11-15T13:29:20.083155+00:00 app[web.1]:
2020-11-15T13:29:20.795200+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:29:20.795248+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:29:20.795250+00:00 app[web.1]: ^
2020-11-15T13:29:20.795250+00:00 app[web.1]:
2020-11-15T13:29:20.795251+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:29:20.795252+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:29:20.795254+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:29:20.795254+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:29:20.795257+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:29:20.795258+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:29:20.810114+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-15T13:29:20.810451+00:00 app[web.1]: npm ERR! errno 1
2020-11-15T13:29:20.817598+00:00 app[web.1]: npm ERR! movie-database#1.0.0 start: `node server.js`
2020-11-15T13:29:20.817850+00:00 app[web.1]: npm ERR! Exit status 1
2020-11-15T13:29:20.818099+00:00 app[web.1]: npm ERR!
2020-11-15T13:29:20.818312+00:00 app[web.1]: npm ERR! Failed at the movie-database#1.0.0 start script.
2020-11-15T13:29:20.818490+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-15T13:29:20.827750+00:00 app[web.1]:
2020-11-15T13:29:20.828041+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-15T13:29:20.828210+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-11-15T13_29_20_819Z-debug.log
2020-11-15T13:29:20.877545+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:29:20.913439+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:29:20.917070+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:29:33.460653+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-15T13:29:36.844587+00:00 app[web.1]:
2020-11-15T13:29:36.844630+00:00 app[web.1]: > movie-database#1.0.0 start /app
2020-11-15T13:29:36.844631+00:00 app[web.1]: > node server.js
2020-11-15T13:29:36.844631+00:00 app[web.1]:
2020-11-15T13:29:38.011159+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:29:38.011219+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:29:38.011220+00:00 app[web.1]: ^
2020-11-15T13:29:38.011220+00:00 app[web.1]:
2020-11-15T13:29:38.011224+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:29:38.011224+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:29:38.011225+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:29:38.011226+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:29:38.011226+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:29:38.011226+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:29:38.011228+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:29:38.011228+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:29:38.011229+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:29:38.046555+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-15T13:29:38.047758+00:00 app[web.1]: npm ERR! errno 1
2020-11-15T13:29:38.059446+00:00 app[web.1]: npm ERR! movie-database#1.0.0 start: node server.js
2020-11-15T13:29:38.059681+00:00 app[web.1]: npm ERR! Exit status 1
2020-11-15T13:29:38.059955+00:00 app[web.1]: npm ERR!
2020-11-15T13:29:38.060192+00:00 app[web.1]: npm ERR! Failed at the movie-database#1.0.0 start script.
2020-11-15T13:29:38.060432+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-15T13:29:38.096793+00:00 app[web.1]:
2020-11-15T13:29:38.097273+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-15T13:29:38.097587+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-11-15T13_29_38_061Z-debug.log
2020-11-15T13:29:38.193702+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:29:38.242866+00:00 heroku[web.1]: State changed from starting to crashed
Server.js
const express = require('express');
const app = express();
const path = require('path');
const cors = require('cors');
const port = process.env.PORT || 5000;
const dotenv = require('dotenv');
const mongoose = require('mongoose');
// Auth Routes
const authRoute = require('./routes/auth');
dotenv.config();
//Connect to DB
mongoose.connect(process.env.DB_CONNECT,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log('connected to DB!')
);
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build/')));
// Middleware
app.use(express.json());
app.use(cors());
// Put all API endpoints under '/api'
app.use('/api', authRoute)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'));
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
Package.json
{
"name": "movie-database",
"version": "1.0.0",
"description": "Small application created with React.js, react router and the movie database to showcase all latest, upcoming and most popular movies.",
"main": "server.js",
"scripts": {
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"joi": "^17.3.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",
"mongoose": "^5.10.12",
"nodemon": "^2.0.6",
"password-generator": "^2.3.2",
"serve": "^11.3.2"
}
}
I cannot figure out what is going wrong?
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.