Trouble hosting project via Heroku - javascript

When I start my project via Heroku I am getting an error saying that "app" is not defined. I have logged "app" and get data back so I do not know why this is happening. Has anyone had this issue before? Here are the errors and the code:
State changed from starting to crashed
2021-05-05T22:16:42.626715+00:00 app[web.1]: /app/listen.js:3
2021-05-05T22:16:42.626744+00:00 app[web.1]: app.listen(PORT, () => console.log(`Listening on ${PORT}...`));
2021-05-05T22:16:42.626745+00:00 app[web.1]: ^
2021-05-05T22:16:42.626745+00:00 app[web.1]:
2021-05-05T22:16:42.626751+00:00 app[web.1]: ReferenceError: app is not defined
2021-05-05T22:16:42.626752+00:00 app[web.1]: at Object.<anonymous> (/app/listen.js:3:1)
2021-05-05T22:16:42.626752+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2021-05-05T22:16:42.626758+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2021-05-05T22:16:42.626758+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:928:32)
2021-05-05T22:16:42.626759+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:769:14)
2021-05-05T22:16:42.626764+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
2021-05-05T22:16:42.626765+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2021-05-05T22:16:42.652119+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-05-05T22:16:42.652547+00:00 app[web.1]: npm ERR! errno 1
2021-05-05T22:16:42.661700+00:00 app[web.1]: npm ERR! be-nc-news#1.0.0 start: `node listen.js`
2021-05-05T22:16:42.661926+00:00 app[web.1]: npm ERR! Exit status 1
2021-05-05T22:16:42.662168+00:00 app[web.1]: npm ERR!
2021-05-05T22:16:42.662387+00:00 app[web.1]: npm ERR! Failed at the be-nc-news#1.0.0 start script.
2021-05-05T22:16:42.662587+00:00 app[web.1]: npm ERR! This is probably not a problem with npm.
app.js:
const express = require("express");
const apiRouter = require("./routes/apiRouter");
const app = express();
const {
handlePsqlErrors,
handleServerErrors,
} = require("./errorHandlingFunctions/errorFunctions");
app.use(express.json());
app.use("/api", apiRouter);
app.use(handlePsqlErrors);
app.use(handleServerErrors);
module.exports = app;
listen.js:
const app = require("./app");
console.log(app);
const { PORT = 9090 } = process.env;
app.listen(PORT, () => console.log(`Listening on port ${PORT}...`));

Related

Node and npm throw error when executing JS file?

I have a simple js file:
const bodyParser = require("body-parser");
const express = require("express");
const app = express();
// Set bodyparser
app.use(bodyParser.urlencoded({ extended : true }));
app.use(express.static('public'));
// Set ejs
app.set('view engine', 'ejs');
app.get("/", (req, res)=>{
console.log("an incoming request...");
res.render("index");
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, ()=>{
console.log("Listening...");
});
When I try to execute it with node server.js, this appears:
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
and with npm start this happens:
> practice#1.0.0 start C:\Users\Youssef\Documents\Practice
> node server.js
C:\Users\Youssef\Documents\Practice\server.js:1
��c
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! practice#1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the practice#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Youssef\AppData\Roaming\npm-cache\_logs\2020-12-31T21_42_52_634Z-debug.log
I don't understand why this happens, there isn't a syntax error in the code and i tested removing the get route.
I cleaned npm cache, reinstalled node modules like in other stackoverflow questions: How to solve npm error "npm ERR! code ELIFECYCLE"
I even reinstalled nodejs and no good.
Thanks in advance.

Pupeeteer heroku buildpack exiting the lunch statement on heroku

This is the error it gives me when I deploy to heroku
It is says that I should check the file "localScrape.js" on line 11 column 21.
I went and included a try/catch block to work my way around it but it is persistently giving me the same error could.
2020-10-02T14:06:40.613205+00:00 app[web.1]: > node index
2020-10-02T14:06:40.613205+00:00 app[web.1]:
2020-10-02T14:06:41.196275+00:00 app[web.1]: Innitializing.....
2020-10-02T14:06:41.197532+00:00 app[web.1]: Starting the server....
2020-10-02T14:06:41.197609+00:00 app[web.1]: Server started..
2020-10-02T14:06:41.197667+00:00 app[web.1]: Server Listening on port 4000
2020-10-02T14:06:41.950485+00:00 app[web.1]: DB Connected successfully
2020-10-02T14:06:47.624092+00:00 app[web.1]: events.js:292
2020-10-02T14:06:47.624104+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-10-02T14:06:47.624105+00:00 app[web.1]: ^
2020-10-02T14:06:47.624105+00:00 app[web.1]:
2020-10-02T14:06:47.624106+00:00 app[web.1]: Error: read ENOTCONN
2020-10-02T14:06:47.624106+00:00 app[web.1]: at tryReadStart (net.js:573:20)
2020-10-02T14:06:47.624107+00:00 app[web.1]: at Socket._read (net.js:584:5)
2020-10-02T14:06:47.624107+00:00 app[web.1]: at Socket.Readable.read (_stream_readable.js:467:10)
2020-10-02T14:06:47.624108+00:00 app[web.1]: at Socket.read (net.js:624:39)
2020-10-02T14:06:47.624108+00:00 app[web.1]: at new Socket (net.js:376:12)
2020-10-02T14:06:47.624109+00:00 app[web.1]: at Object.Socket (net.js:267:41)
2020-10-02T14:06:47.624109+00:00 app[web.1]: at createSocket (internal/child_process.js:314:14)
2020-10-02T14:06:47.624109+00:00 app[web.1]: at ChildProcess.spawn (internal/child_process.js:437:23)
2020-10-02T14:06:47.624110+00:00 app[web.1]: at Object.spawn (child_process.js:548:9)
2020-10-02T14:06:47.624110+00:00 app[web.1]: at BrowserRunner.start (/app/node_modules/puppeteer/lib/launcher/BrowserRunner.js:51:34)
2020-10-02T14:06:47.624111+00:00 app[web.1]: at ChromeLauncher.launch (/app/node_modules/puppeteer/lib/Launcher.js:64:16)
2020-10-02T14:06:47.624111+00:00 app[web.1]: at async localScrape (/app/Scraper/localScrape.js:11:21)
2020-10-02T14:06:47.624111+00:00 app[web.1]: at async doScraping (/app/index.js:20:3)
2020-10-02T14:06:47.624112+00:00 app[web.1]: Emitted 'error' event on Socket instance at:
2020-10-02T14:06:47.624112+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2020-10-02T14:06:47.624112+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2020-10-02T14:06:47.624113+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-10-02T14:06:47.624113+00:00 app[web.1]: errno: 'ENOTCONN',
2020-10-02T14:06:47.624114+00:00 app[web.1]: code: 'ENOTCONN',
2020-10-02T14:06:47.624114+00:00 app[web.1]: syscall: 'read'
2020-10-02T14:06:47.624114+00:00 app[web.1]: }
2020-10-02T14:06:47.643941+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-10-02T14:06:47.644301+00:00 app[web.1]: npm ERR! errno 1
2020-10-02T14:06:47.648553+00:00 app[web.1]: npm ERR! scraping-script-for-news#1.0.0 start: `node index`
2020-10-02T14:06:47.648770+00:00 app[web.1]: npm ERR! Exit status 1
2020-10-02T14:06:47.649014+00:00 app[web.1]: npm ERR!
2020-10-02T14:06:47.649222+00:00 app[web.1]: npm ERR! Failed at the scraping-script-for-news#1.0.0 start script.
2020-10-02T14:06:47.649428+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-10-02T14:06:49.194170+00:00 app[web.1]:
2020-10-02T14:06:49.194363+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-10-02T14:06:49.194480+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-10-02T14_06_47_651Z-debug.log
2020-10-02T14:06:49.249822+00:00 heroku[web.1]: Process exited with status 1
2020-10-02T14:06:49.281443+00:00 heroku[web.1]: State changed from starting to crashed```

how to fix heroku error while deploying an expressjs app?

I've been trying to fix a heroku api but I keep getting an error which I cant fix. The app is not even running, it goes straight to the error. It was working until I recently made an update to the api.
The error is shown as
2019-10-18T21:40:06.936984+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:585:3)
2019-10-18T21:40:06.936986+00:00 app[web.1]: at Module.require
(internal/modules/cjs/loader.js:692:17)
2019-10-18T21:40:06.936988+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:25:18)
2019-10-18T21:40:06.936989+00:00 app[web.1]: at Object.<anonymous> (/app/routes/api.js:7:16)
2019-10-18T21:40:06.936991+00:00 app[web.1]: at Module._compile
(internal/modules/cjs/loader.js:778:30)
2019-10-18T21:40:06.944691+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-10-18T21:40:06.945081+00:00 app[web.1]: npm ERR! errno 1
2019-10-18T21:40:06.946204+00:00 app[web.1]: npm ERR! quickJobs-api#1.0.0 start: `node
server.js`
2019-10-18T21:40:06.946319+00:00 app[web.1]: npm ERR! Exit status 1
2019-10-18T21:40:06.946542+00:00 app[web.1]: npm ERR!
2019-10-18T21:40:06.946663+00:00 app[web.1]: npm ERR! Failed at the quickJobs-api#1.0.0 start script.
2019-10-18T21:40:06.946779+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-10-18T21:40:06.953214+00:00 app[web.1]:
2019-10-18T21:40:06.953367+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-10-18T21:40:06.953452+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-10-18T21_40_06_948Z-debug.log
2019-10-18T21:40:07.008783+00:00 heroku[web.1]: Process exited with status 1
2019-10-18T21:40:24.571093+00:00 heroku[web.1]: State changed from crashed to starting
2019-10-18T22:05:16.977483+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=quickjobsapi.herokuapp.com request_id=a50a5c3e-7152-4ce1-942f-df572188531b fwd="63.143.196.162" dyno= connect= serv
ice= status=503 bytes= protocol=https
2019-10-18T22:05:17.639126+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=quickjobsapi.herokuapp.com request_id=405f9fd7-ae38-478e-b182-7e5306ab0fa6 fwd="63.143.196.162" dyno= co
nnect= service= status=503 bytes= protocol=https
2019-10-18T22:05:48.086732+00:00 heroku[web.1]: State changed from crashed to starting
2019-10-18T22:05:50.688489+00:00 heroku[web.1]: Starting process with command `npm start`
2019-10-18T22:05:53.119843+00:00 app[web.1]:
2019-10-18T22:05:53.119869+00:00 app[web.1]: > quickJobs-api#1.0.0 start /app
2019-10-18T22:05:53.119871+00:00 app[web.1]: > node server.js
2019-10-18T22:05:53.119872+00:00 app[web.1]:
2019-10-18T22:05:54.001916+00:00 heroku[web.1]: State changed from starting to crashed
2019-10-18T22:05:53.873724+00:00 app[web.1]: internal/modules/cjs/loader.js:807
2019-10-18T22:05:53.873754+00:00 app[web.1]: return process.dlopen(module, path.toNamespacedPath(filename));
2019-10-18T22:05:53.873756+00:00 app[web.1]: ^
2019-10-18T22:05:53.873758+00:00 app[web.1]:
2019-10-18T22:05:53.873760+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2019-10-18T22:05:53.873761+00:00 app[web.1]: at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
2019-10-18T22:05:53.873763+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-10-18T22:05:53.873765+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-10-18T22:05:53.873767+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-10-18T22:05:53.873768+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-10-18T22:05:53.873770+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-10-18T22:05:53.873771+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2019-10-18T22:05:53.873773+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-10-18T22:05:53.882321+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-10-18T22:05:53.882732+00:00 app[web.1]: npm ERR! errno 1
2019-10-18T22:05:53.883970+00:00 app[web.1]: npm ERR! quickJobs-api#1.0.0 start: `node server.js`
2019-10-18T22:05:53.884082+00:00 app[web.1]: npm ERR! Exit status 1
2019-10-18T22:05:53.884277+00:00 app[web.1]: npm ERR!
2019-10-18T22:05:53.884398+00:00 app[web.1]: npm ERR! Failed at the quickJobs-api#1.0.0 start script.
2019-10-18T22:05:53.884514+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-10-18T22:05:53.914312+00:00 app[web.1]:
2019-10-18T22:05:53.914489+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-10-18T22:05:53.914584+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-10-18T22_05_53_885Z-debug.log
2019-10-18T22:05:54.019964+00:00 heroku[web.1]: State changed from crashed to starting
2019-10-18T22:05:53.977749+00:00 heroku[web.1]: Process exited with status 1
2019-10-18T22:05:57.322980+00:00 heroku[web.1]: Starting process with command `npm start`
2019-10-18T22:06:00.008642+00:00 app[web.1]:
2019-10-18T22:06:00.008674+00:00 app[web.1]: > quickJobs-api#1.0.0 start /app
2019-10-18T22:06:00.008676+00:00 app[web.1]: > node server.js
2019-10-18T22:06:00.008678+00:00 app[web.1]:
2019-10-18T22:06:00.907169+00:00 app[web.1]: internal/modules/cjs/loader.js:807
2019-10-18T22:06:00.907208+00:00 app[web.1]: return process.dlopen(module, path.toNamespacedPath(filename));
2019-10-18T22:06:00.907211+00:00 app[web.1]: ^
2019-10-18T22:06:00.907214+00:00 app[web.1]:
2019-10-18T22:06:00.907216+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2019-10-18T22:06:00.907218+00:00 app[web.1]: at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
2019-10-18T22:06:00.907220+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-10-18T22:06:00.907223+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-10-18T22:06:00.907225+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-10-18T22:06:00.907228+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-10-18T22:06:00.907229+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-10-18T22:06:00.907232+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2019-10-18T22:06:00.907234+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-10-18T22:06:00.907235+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-10-18T22:06:00.907238+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-10-18T22:06:00.907242+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-10-18T22:06:00.907244+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-10-18T22:06:00.907247+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-10-18T22:06:00.907249+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-10-18T22:06:00.907251+00:00 app[web.1]: at Object.<anonymous> (/app/routes/api.js:7:16)
2019-10-18T22:06:00.907253+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-10-18T22:06:00.925298+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-10-18T22:06:00.925759+00:00 app[web.1]: npm ERR! errno 1
2019-10-18T22:06:00.926956+00:00 app[web.1]: npm ERR! quickJobs-api#1.0.0 start: `node server.js`
2019-10-18T22:06:00.927125+00:00 app[web.1]: npm ERR! Exit status 1
2019-10-18T22:06:00.927387+00:00 app[web.1]: npm ERR!
2019-10-18T22:06:00.927644+00:00 app[web.1]: npm ERR! Failed at the quickJobs-api#1.0.0 start script.
2019-10-18T22:06:00.927832+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-10-18T22:06:00.942491+00:00 app[web.1]:
2019-10-18T22:06:00.942496+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-10-18T22:06:00.942498+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-10-18T22_06_00_929Z-debug.log
2019-10-18T22:06:01.013650+00:00 heroku[web.1]: State changed from starting to crashed
2019-10-18T22:06:00.991627+00:00 heroku[web.1]: Process exited with status 1
Git
2019-10-18T22:06:00.778487+00:00 heroku[web.1]: State changed from starting to up
2019-10-18T22:06:01.574620+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=quickjobsapi.herokuapp.com request_id=e500ac9e-cc2f-4cde-9f91-8424f36c57f2 fwd="63.143.196.162" dyno= connect= serv
ice= status=503 bytes= protocol=https
2019-10-18T22:06:02.282334+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=quickjobsapi.herokuapp.com request_id=38013505-dfbc-4e8a-90e4-e55077f9b467 fwd="63.143.196.162" dyno= co
nnect= service= status=503 bytes= protocol=https
My server.js file has
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const app = express()
app.use(cors())
//const PORT = process.env.PORT || 3000;
app.listen(process.env.PORT || 3000,function(){
console.log('server has been started')
})
app.use(bodyParser.json({limit: "500mb"}));
app.use(bodyParser.urlencoded({limit: "500mb", extended: true, parameterLimit:50000}));
app.use('/api',require('./routes/api'))
The other files are just the api and the schema for mongodb.
Please help
I see that there is a bcrypt related error. Are you using different Node.js version on your local dev and your prod? If yes then try to ignore the package manager lock file yarn.lock or package-lock.json.
lock file usually "hold" version specific dependency, in some case package with native dependency like bcrypt can cause some issue.

Vue | How to change port number to 80 for web?

So I'm trying to deploy my vue app and for testing I want to switch my port 80 so I can see links without the :8080 extension. When I do this I get a fatal error
> node build/dev-server.js
> Starting dev server...
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EACCES 0.0.0.0:80
at Server.setupListenHandle [as _listen2] (net.js:1343:19)
at listenInCluster (net.js:1401:12)
at Server.listen (net.js:1485:7)
at Function.listen (/Users/Maceto/Desktop/sts/StsSnag/client/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/Users/Maceto/Desktop/sts/StsSnag/client/build/dev-server.js:85:18)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client#1.0.0 start: `node build/dev-server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Maceto/.npm/_logs/2019-02-28T21_07_27_188Z-debug.log
I'm not sure what I'm doing wrong I changed the port in the config file but I get this. This also only happens on port 80.
You have to either do
sudo node build/dev-server.js
or
sudo setcap 'cap_net_bind_service=+ep' /path/to/nodejs
and then you'll be able to do it without sudo

"Cannot find module 'async'" error when trying to deploy to Heroku

When trying to deploy to Heroku I didn't have a problem however when trying to access my Heroku URL I got an "Application error". After executing heroku logs, I got the error Cannot find module 'async'. I installed it and I am async/await only inside this function. Could someone help me solve this issue?
const express = require('express');
const router = express.Router();
const Rental = require('../models/rental');
const User = require('../models/user');
const { normalizedErrors } = require('../helpers/mongoose')
var flatten = require('array-flatten')
var Promise = require('Promise');
var async = require('async');
router.get('', async function (req, res) {
let finalResults = [];
let dummyArray = [''];
let resolvedFinalArray = await Promise.all(dummyArray.map(async (value) => {
const result = await getRentalsByQuery({});
finalValue = result;
return finalValue;
}));
finalResults.push(resolvedFinalArray);
finalResults = flatten(finalResults);
if (req.query.filters) {
const queryObj = JSON.parse(req.query.filters);
if (queryObj.title) {
// SOME ASYNC OPERATIONS with foundRentals
}
}
//clean resolvedFinalArray for sending as a simple array json
finalResults = flatten(finalResults)
res.json(finalResults);
});
Here is the error detail:
2018-12-08T06:09:01.416754+00:00 app[web.1]:
2018-12-08T06:09:02.649330+00:00 app[web.1]: internal/modules/cjs/loader.js:582
2018-12-08T06:09:02.649344+00:00 app[web.1]: throw err;
2018-12-08T06:09:02.649346+00:00 app[web.1]: ^
2018-12-08T06:09:02.649347+00:00 app[web.1]:
2018-12-08T06:09:02.649348+00:00 app[web.1]: Error: Cannot find module 'async'
2018-12-08T06:09:02.649350+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
2018-12-08T06:09:02.649351+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:506:25)
2018-12-08T06:09:02.649353+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:636:17)
2018-12-08T06:09:02.649354+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:20:18)
2018-12-08T06:09:02.649355+00:00 app[web.1]: at Object.<anonymous> (/app/server/routes/rentals.js:8:13)
2018-12-08T06:09:02.649357+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-12-08T06:09:02.649358+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-12-08T06:09:02.649359+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-12-08T06:09:02.649361+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2018-12-08T06:09:02.649362+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:529:3)
2018-12-08T06:09:02.649363+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:636:17)
2018-12-08T06:09:02.649364+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:20:18)
2018-12-08T06:09:02.649365+00:00 app[web.1]: at Object.<anonymous> (/app/server/index.js:8:22)
2018-12-08T06:09:02.649367+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-12-08T06:09:02.649368+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-12-08T06:09:02.649369+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-12-08T06:09:02.672674+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-08T06:09:02.673564+00:00 app[web.1]: npm ERR! errno 1
2018-12-08T06:09:02.676119+00:00 app[web.1]: npm ERR! server#1.0.0 start: `node index.js`
2018-12-08T06:09:02.676416+00:00 app[web.1]: npm ERR! Exit status 1
2018-12-08T06:09:02.677167+00:00 app[web.1]: npm ERR!
2018-12-08T06:09:02.677417+00:00 app[web.1]: npm ERR! Failed at the server#1.0.0 start script.
2018-12-08T06:09:02.677805+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-12-08T06:09:02.696205+00:00 app[web.1]: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2018-12-08T06:09:02.697621+00:00 app[web.1]:
2018-12-08T06:09:02.698037+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-12-08T06:09:02.698297+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-12-08T06_09_02_682Z-debug.log
2018-12-08T06:09:02.713718+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-08T06:09:02.714599+00:00 app[web.1]: npm ERR! errno 1
2018-12-08T06:09:02.718363+00:00 app[web.1]: npm ERR! angular-starter#0.0.0 start: `npm run start --prefix server`
2018-12-08T06:09:02.718847+00:00 app[web.1]: npm ERR! Exit status 1
2018-12-08T06:09:02.719560+00:00 app[web.1]: npm ERR!
2018-12-08T06:09:02.719990+00:00 app[web.1]: npm ERR! Failed at the angular-starter#0.0.0 start script.
2018-12-08T06:09:02.720570+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-12-08T06:09:02.735159+00:00 app[web.1]:
2018-12-08T06:09:02.735523+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-12-08T06:09:02.735769+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-12-08T06_09_02_724Z-debug.log
2018-12-08T06:09:14.369444+00:00 app[web.1]:
2018-12-08T06:09:14.369473+00:00 app[web.1]: > angular-starter#0.0.0 start /app
2018-12-08T06:09:14.369475+00:00 app[web.1]: > npm run start --prefix server
2018-12-08T06:09:14.369477+00:00 app[web.1]:
2018-12-08T06:09:15.403449+00:00 app[web.1]:
2018-12-08T06:09:15.403494+00:00 app[web.1]: > server#1.0.0 start /app/server
2018-12-08T06:09:15.403496+00:00 app[web.1]: > node index.js
2018-12-08T06:09:15.403497+00:00 app[web.1]:
Check 'async' in node_modules ,because your loader log "Cannot find module 'async'"
first npm i --save async, then restart your app

Categories

Resources