Syntax error on express app.use - node.js

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.

Related

can't get heroku to find my custom module in node.js

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

ERROR : hosting Ecommerce web application in Heroku

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

mdb with node js hosted on Heroku does not work

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]: }

Cannot deploy an app on Heroku

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?

Testing Inversify w/ Mocha causes strange error ERROR_MSGS.NULL_ARGUMENT

I'm getting the following error when I try to test my code with Mocha/Chai.
Has anyone else seen this error?
/Users/me/Sites/my_project/node_modules/inversify/lib/container/lookup.js:13
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
^
Error: NULL argument
at Lookup.add (/Users/me/Sites/my_project/node_modules/inversify/lib/container/lookup.js:13:19)
at Container.bind (/Users/me/Sites/my_project/node_modules/inversify/lib/container/container.js:121:33)
at Object. (/Users/me/Sites/my_project/test/api-temp/dependency-injection.js:9:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (/Users/me/Sites/my_project/test/api-temp/services/some.service.js:21:32)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (/Users/me/Sites/my_project/test/api-temp/services/some.service.spec.js:4:24)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at /Users/me/Sites/my_project/node_modules/mocha/lib/mocha.js:222:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/me/Sites/my_project/node_modules/mocha/lib/mocha.js:219:14)
at Mocha.run (/Users/me/Sites/my_project/node_modules/mocha/lib/mocha.js:487:10)
at Object. (/Users/me/Sites/facecards-api/node_modules/mocha/bin/_mocha:459:18)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
npm ERR! Darwin 16.5.0
npm ERR! argv "/Users/me/.nvm/v4.4.5/bin/node" "/Users/dan/.nvm/v4.4.5/bin/npm" "run" "test-api" "-w"
npm ERR! node v4.4.5
npm ERR! npm v2.15.5
npm ERR! code ELIFECYCLE
npm ERR! my_project#1.0.0 test-api: `mocha -R spec './test/api-temp/**/*.spec.js' --reporter min --inline-diffs`
npm ERR! Exit status 1
The problem occurs when I try to new up the class in my test code.
describe('SomeService', () => {
let someService: any
someService = new SomeService(null, null, null)
mockFunction = sinon.createStubInstance(someService, 'function')
describe('#function', () => {
beforeEach(() => {
result = someService.function(1234)
})
it('should call function', () => {
expect(.callCount).to.eql(1)
})
})
})

Resources