I am trying to deploy an application to Heroku, but after deployment in the logs I get the following error:
2017-08-09T09:32:39.071603+00:00 app[web.1]:
2017-08-09T09:32:39.876049+00:00 app[web.1]: /app/main.js:38
2017-08-09T09:32:39.876059+00:00 app[web.1]: app.set('port', (process.env.PORT || 5000));
2017-08-09T09:32:39.876060+00:00 app[web.1]: ^
2017-08-09T09:32:39.876060+00:00 app[web.1]:
2017-08-09T09:32:39.876063+00:00 app[web.1]: TypeError: Cannot read property 'PORT' of undefined
2017-08-09T09:32:39.876063+00:00 app[web.1]: at Object.<anonymous> (/app/main.js:38:29)
2017-08-09T09:32:39.876064+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-08-09T09:32:39.876065+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-08-09T09:32:39.876065+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-08-09T09:32:39.876068+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-08-09T09:32:39.876069+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-08-09T09:32:39.876069+00:00 app[web.1]: at Module.runMain (module.js:604:10)
2017-08-09T09:32:39.876070+00:00 app[web.1]: at run (bootstrap_node.js:389:7)
2017-08-09T09:32:39.876070+00:00 app[web.1]: at startup (bootstrap_node.js:149:9)
2017-08-09T09:32:39.876071+00:00 app[web.1]: at bootstrap_node.js:504:3
I get the same error when I try to run the application locally
11:26:03 web.1 | var port = process.env.PORT || 5000;
11:26:03 web.1 | ^
11:26:03 web.1 | TypeError: Cannot read property 'PORT' of undefined
Does someone know what am I doing wrong?
Related
I am trying to deploy a node.js app to heroku. But I am facing this ("Error: Cannot find module '../models/people' ) error. The app is working fine in localhost.
2022-11-01T17:45:47.000000+00:00 app[api]: Build succeeded
2022-11-01T17:45:47.265323+00:00 heroku[web.1]: State changed from crashed to starting
2022-11-01T17:45:50.307944+00:00 heroku[web.1]: Starting process with command `NODE_ENV=production node index.js`
2022-11-01T17:45:52.192313+00:00 app[web.1]: node:internal/modules/cjs/loader:936
2022-11-01T17:45:52.192350+00:00 app[web.1]: throw err;
2022-11-01T17:45:52.192350+00:00 app[web.1]: ^
2022-11-01T17:45:52.192351+00:00 app[web.1]:
2022-11-01T17:45:52.192351+00:00 app[web.1]: Error: Cannot find module '../models/people'
2022-11-01T17:45:52.192351+00:00 app[web.1]: Require stack:
2022-11-01T17:45:52.192351+00:00 app[web.1]: - /app/controller/login_controller.js
2022-11-01T17:45:52.192352+00:00 app[web.1]: - /app/router/login_router.js
2022-11-01T17:45:52.192352+00:00 app[web.1]: - /app/index.js
2022-11-01T17:45:52.192352+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-11-01T17:45:52.192353+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-11-01T17:45:52.192353+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-11-01T17:45:52.192353+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-11-01T17:45:52.192354+00:00 app[web.1]: at Object.<anonymous> (/app/controller/login_controller.js:2:14)
2022-11-01T17:45:52.192354+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-11-01T17:45:52.192354+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
2022-11-01T17:45:52.192355+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-11-01T17:45:52.192355+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-11-01T17:45:52.192355+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-11-01T17:45:52.192355+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-11-01T17:45:52.192356+00:00 app[web.1]: requireStack: [
2022-11-01T17:45:52.192356+00:00 app[web.1]: '/app/controller/login_controller.js',
2022-11-01T17:45:52.192356+00:00 app[web.1]: '/app/router/login_router.js',
2022-11-01T17:45:52.192357+00:00 app[web.1]: '/app/index.js'
2022-11-01T17:45:52.192357+00:00 app[web.1]: ]
2022-11-01T17:45:52.192357+00:00 app[web.1]: }
2022-11-01T17:45:52.307078+00:00 heroku[web.1]: Process exited with status 1
2022-11-01T17:45:52.382922+00:00 heroku[web.1]: State changed from starting to crashed
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
Well i build a web application for an online e-commerce store project as a sample project. It was doing prefectly well until i decided to put it online in heroku and now the project keeps giving an error in heroku:
Error:
2022-05-31T09:50:32.498928+00:00 app[web.1]: Error: Cannot find module './debug'
2022-05-31T09:50:32.498928+00:00 app[web.1]: Require stack:
2022-05-31T09:50:32.498928+00:00 app[web.1]: - /app/node_modules/mquery/node_modules/debug/src/node.js
2022-05-31T09:50:32.498929+00:00 app[web.1]: - /app/node_modules/mquery/node_modules/debug/src/index.js
2022-05-31T09:50:32.498929+00:00 app[web.1]: - /app/node_modules/mquery/lib/mquery.js
2022-05-31T09:50:32.498929+00:00 app[web.1]: - /app/node_modules/mongoose/lib/promise_provider.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/utils.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/statemachine.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/internal.js
2022-05-31T09:50:32.498931+00:00 app[web.1]: - /app/node_modules/mongoose/lib/document.js
2022-05-31T09:50:32.498931+00:00 app[web.1]: - /app/node_modules/mongoose/lib/index.js
2022-05-31T09:50:32.498931+00:00 app[web.1]: - /app/node_modules/mongoose/index.js
2022-05-31T09:50:32.498932+00:00 app[web.1]: - /app/Backend/models/product.js
2022-05-31T09:50:32.498932+00:00 app[web.1]: - /app/Backend/controllers/products.js
2022-05-31T09:50:32.498932+00:00 app[web.1]: - /app/Backend/routes/products.js
2022-05-31T09:50:32.498933+00:00 app[web.1]: - /app/Backend/app.js
2022-05-31T09:50:32.498933+00:00 app[web.1]: - /app/Backend/server.js
2022-05-31T09:50:32.498933+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-05-31T09:50:32.498934+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-05-31T09:50:32.498934+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mquery/node_modules/debug/src/node.js:14:28)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-31T09:50:32.498936+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-31T09:50:32.498936+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-31T09:50:32.498937+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-05-31T09:50:32.498937+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-05-31T09:50:32.498937+00:00 app[web.1]: requireStack: [
2022-05-31T09:50:32.498937+00:00 app[web.1]: '/app/node_modules/mquery/node_modules/debug/src/node.js',
2022-05-31T09:50:32.498937+00:00 app[web.1]: '/app/node_modules/mquery/node_modules/debug/src/index.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mquery/lib/mquery.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mongoose/lib/promise_provider.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mongoose/lib/utils.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/statemachine.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/internal.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/document.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/index.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/node_modules/mongoose/index.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/Backend/models/product.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/Backend/controllers/products.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/Backend/routes/products.js',
2022-05-31T09:50:32.498941+00:00 app[web.1]: '/app/Backend/app.js',
2022-05-31T09:50:32.498941+00:00 app[web.1]: '/app/Backend/server.js'
I'm worried to of what have happened this is the first time im learning this . Thanks in advance.
Git: GIT
I used 'node-adodb' nodejs module with .mdb database. Here is my code.
const ADODB = require('node-adodb');
const connection = ADODB.open(`Provider=Microsoft.Jet.OLEDB.4.0;Data Source=${__dirname}/data/Database.mdb;`);
module.exports = { connection : connection };
This is worked on a local and throws the following error after hosted on Heroku.
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
2020-04-23T21:53:16.421683+00:00 app[web.1]: ^
2020-04-23T21:53:16.421683+00:00 app[web.1]:
2020-04-23T21:53:16.421684+00:00 app[web.1]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
2020-04-23T21:53:16.421684+00:00 app[web.1]: at validateString (internal/validators.js:117:11)
2020-04-23T21:53:16.421685+00:00 app[web.1]: at Object.join (path.js:1039:7)
2020-04-23T21:53:16.421686+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/node-adodb/lib/engine.js:16:24)
2020-04-23T21:53:16.421686+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1156:30)
2020-04-23T21:53:16.421687+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
2020-04-23T21:53:16.421687+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1000:32)
2020-04-23T21:53:16.421687+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:899:14)
2020-04-23T21:53:16.421688+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1042:19)
2020-04-23T21:53:16.421688+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-04-23T21:53:16.421688+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/node-adodb/index.js:11:16) {
2020-04-23T21:53:16.421689+00:00 app[web.1]: code: 'ERR_INVALID_ARG_TYPE'
2020-04-23T21:53:16.421689+00:00 app[web.1]: }
I have used this code with my node.js application with express but when uploading to Heroku I get an error when running.
2016-09-28T11:01:40.502448+00:00 app[web.1]: /app/routes/index.js:146
2016-09-28T11:01:40.502467+00:00 app[web.1]: app.use(({method, url}, rsp, next) => {
2016-09-28T11:01:40.502468+00:00 app[web.1]: ^
2016-09-28T11:01:40.502468+00:00 app[web.1]:
2016-09-28T11:01:40.502469+00:00 app[web.1]: SyntaxError: Unexpected token {
2016-09-28T11:01:40.502469+00:00 app[web.1]: at exports.runInThisContext (vm.js:53:16)
2016-09-28T11:01:40.502470+00:00 app[web.1]: at Module._compile (module.js:387:25)
2016-09-28T11:01:40.502471+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-09-28T11:01:40.502471+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-09-28T11:01:40.502472+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-09-28T11:01:40.502473+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-09-28T11:01:40.502473+00:00 app[web.1]: at require (internal/module.js:20:19)
2016-09-28T11:01:40.502474+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:8:14)
2016-09-28T11:01:40.502474+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-09-28T11:01:40.502475+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
My code is
app.use(({method, url}, rsp, next) => {
rsp.on('finish', () => {
console.log(`${rsp.statusCode} ${method} ${url}`);
});
next();
});
Any help would be much appreciated
In your package.json, do you specify the node engine?
"engines": {
"node": "6.5.0"
}
I would have just added this as a comment, but I don't have enough rep.