Node.js v17.5.0 [nodemon] app crashed - waiting for file changes before starting - node.js

Creating node.js connection with mongodb.
MongoDb connection in error
Not getting app is running 8000 and shows "nodemon app crashed waiting for file changes before starting "
const mongoose = require('mongoose');
const express = require("express");
const app=express();
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser:true});
const port=8000;
app.listen(port,()=>{
console.log(`App is running at ${port}`);
});
Error Caused:
TypeError: Cannot assign to read only property 'map' of object '#'
at Object. (/Users/praneypareek/Desktop/MERN Working Project/projbackend/node_modules/mongoose/lib/cursor/QueryCursor.js:150:27)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/Users/praneypareek/Desktop/MERN Working Project/projbackend/node_modules/mongoose/lib/query.js:12:21)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/Users/praneypareek/Desktop/MERN Working Project/projbackend/node_modules/mongoose/lib/index.js:27:15)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
Node.js v17.5.0
[nodemon] app crashed - waiting for file changes before starting...

The latest release of Node.JS is what is causing this issue. In your package.json, make sure to set your engine to"engines": { "node": ">=0.12 < 17.5.0" } and you should be fine.
Solution which worked well for me:)
Step 01: Open your terminal and copy paste below command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | zsh
Wait patiently until its done.
Step 02: sudo vim ./zshrc
Step 03: Press I for Insert Mode and copy paste below command. Must be same in three lines.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
then press ESC key :wq (write and quite).
Step 04: brew install nvm
step 05: nvm install node (which will download latest version node)
step 06: nvm ls-remote (which make all the version available)
step 07: nvm install 14 (An Example)
step 08: nvm use 14 (this make it as default version)
source: https://github.com/nvm-sh/nvm

Related

Can't Make Strapi API Requests Receiving error: Module Did not self-register

I'm unable to make any API using the Strapi api without getting the below error message.
/Users/xxxxxxxxxxxxx/node_modules/snappy/build/Release/binding.node'.
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at bindings (/Users/xxxxxxxxxxxxx/node_modules/bindings/bindings.js:112:48)
at Object.<anonymous> (/Users/xxxxxxxxxxxxx/node_modules/snappy/snappy.js:2:34)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at Object.require (internal/modules/cjs/helpers.js:101:18)
at _optionalRequire (/Users/xxxxxxxxxxxxx/Documents/xxxxxxxxxxx/node_modules/mongodb/node_modules/optional-require/dist/index.js:111:65)
at x (/Users/xxxxxxxxxxxxx/Documents/xxxxxxxxxxx/node_modules/mongodb/node_modules/optional-require/dist/index.js:172:16)
at Object.retrieveSnappy (/Users/xxxxxxxxxxxxx/Documents/xxxxxxxxxxx/node_modules/mongodb/lib/core/connection/utils.js:49:18)
at Object.<anonymous> (/Users/xxxxxxxxxxxxx/Documents/xxxxxxxxxxx/node_modules/mongodb/lib/core/wireprotocol/compression.js:3:47)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
This error shows up even when I simply do the following:
Run npx create-strapi-app#latest my-project --quickstart
Make a Postman request to /api/auth/local/register/
I expect a user to get created and have a token returned. Instead the above error is shown in the console and a 500 internal error is returned in Postman.
System
Node.js version: v14.19
NPM version:6.14.13
Strapi version: 4.0.7
Database: I've tried with Postgres and SQLLite
Operating system: MacOS 11.6
I've read all the StackOverflow posts regarding this and I've deleted and reinstalled the node_modules file numerous times. I've created multiple Strapi Projects and the same thing happens on all of them.
The interesting part is that I setup one instance with a Dockerfile and deployed this instance to ElasticBeanstalk with a database connecting to an RDS instance.
FROM strapi/base
WORKDIR /strapi-app
COPY ./package.json ./
COPY ./yarn.lock ./
RUN yarn install
COPY . .
ENV NODE_ENV development
RUN yarn build
EXPOSE 1337
CMD ["yarn", "start"]
When I try to run the API commands on that instance they work without an issue. I've exhausted all resources I can think of and I'm still unable to resolve this issue.
UPDATE:
I've since removed all other versions from NVM.
nvm list
v14.19.0
system
I also went out to nodejs.org and downloaded the latest package so my system is using v16.13.2.
Once again removed node_modules and reinstalled. Still the same problem.
I have this in my .bash_profile
###NVM CONFIG###
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion" ] && . "/usr/local/opt/nvm/etc/bash_completion" #This loads nvm bash_completion
I came across the same problem, try this
npm install snappy

Strapi develop script not working with PM2

I am trying to run Strapi in development mode with pm2 by using this command:
pm2 start npm --name myprojectname -- run develop
Unfortunately, I get the following error
0|edtech-a | SyntaxError: Unexpected token ':'
0|edtech-a | at wrapSafe (internal/modules/cjs/loader.js:979:16)
0|edtech-a | at Module._compile (internal/modules/cjs/loader.js:1027:27)
0|edtech-a | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|edtech-a | at Module.load (internal/modules/cjs/loader.js:928:32)
0|edtech-a | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
0|edtech-a | at Object.<anonymous> (C:\Users\dimit\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
0|edtech-a | at Module._compile (internal/modules/cjs/loader.js:1063:30)
0|edtech-a | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|edtech-a | at Module.load (internal/modules/cjs/loader.js:928:32)
0|edtech-a | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
PM2 version is 4.5.1
NodeJS version is 14.15.4
NPM version is 6.13.2
Strapi version is 3.1.0-alpha.5
I get the same error when I try to run Strapi in development mode through an ecosystem.config.json file as well.
Has somebody faced this issue, if yes, how can I solve it?
Yeah, I encountered some problems myself and decided to go for a workaround:
Create a script with the commands you would type normally:
touch strapi.sh
Type in your desired commands:
nano strapi.sh
cd my-strapi-project
npm run develop
Close and save (Crtl+x then type "y" and press enter).
Now just start that file with pm2
pm2 start strapi.sh
Check if everything works fine
pm2 logs
Thats it.
Can you try with this:
pm2 start npm --name myprojectname --interpreter bash -- run develop
UPDATED
for yarn
pm2 start yarn --name myprojectname --interpreter bash -- run develop

Error: Cannot find module 'C:\server.js' in Node server for Meanjs

I have git cloned meanjs into a folder in D: drive as shown below and ran the command npm start to start the node server.
admin#admin-PC MINGW32 /d/Udemy Angular 1 projects/Project5/jobfinder (master)
$ npm start
> meanjs#0.5.0 start D:\Udemy Angular 1 projects\Project5\jobfinder
> gulp
[23:41:30] Using gulpfile D:\Udemy Angular 1 projects\Project5\jobfinder\gulpfile.js
....and got the below error.
Error: Cannot find module 'C:\server.js'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
[23:58:35] [nodemon] app crashed - waiting for file changes before starting...
After that, just to give it a try I copied the server.js from the current directory to C:\ and issued 'npm start' command at git bash from the same directory and the error changed to below.
Debugger listening on [::]:5858
module.js:457
throw err;
^
Error: Cannot find module './config/lib/app'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\server.js:6:11)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
[23:41:52] [nodemon] app crashed - waiting for file changes before starting...
Can anyone please help me understand why is Node looking for server.js and other resources at C:\ instead of the current directory? Is there anything very simple I am missing out (though I find it quite strange !). Btw sorry for posting the git bash errors as code since I did not have enough reputations to post more than one image link.
Cheers!
Adding my research ....
Invoking 'npm start' command in meanjs directory hits the file gulpfile.js. Looking into the file, I saw that a gulp task (nodemon) was initiated as below and the script property of the return object was set to 'server.js'.
Code from gulpfile.js.
gulp.task('nodemon', function () {
var nodeVersions = process.versions;
var debugArgument = '--debug';
switch (nodeVersions.node.substr(0, 1)) {
case '4':
case '5':
case '6':
debugArgument = '--debug';
break;
case '7':
debugArgument = '--inspect';
break;
}
console.log('nodemon task'); // checking execution of the callback
return plugins.nodemon({
script: 'server.js',
nodeArgs: [debugArgument],
ext: 'js,html',
verbose: true,
watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
});
});
The above problem was solved by deleting the Autorun string in the registry at the below path.
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor".
The autorun string was set to C: and as a result Nodemon recognised C: as the root instead of the current directory in Gitbash or command prompt.

Cannot run node module as service

I'm trying to run the node module npm-lazy as a service in my localzone.
If I run the start command on the commandline It works well. I'm running it with:
npm_lazy --config /etc/npm-lazy-config.js
But if want to run the module as a service it constantly gets this errormessage:
[ Apr 9 01:13:31 Executing start method ("/opt/local/bin/npm_lazy --config /etc/npm-lazy-config.js"). ]
path.js:336
var isAbsolute = path.charAt(0) === '/',
^
TypeError: Cannot call method 'charAt' of undefined
at Object.exports.normalize (path.js:336:27)
at Object.<anonymous> (/opt/local/lib/node_modules/npm_lazy/config.js:2:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/opt/local/lib/node_modules/npm_lazy/bin/npm_lazy:37:14)
at Module._compile (module.js:456:26)
[ Apr 9 01:13:32 Stopping because service exited with an error. ]
[ Apr 9 01:13:32 Executing start method ("/opt/local/bin/npm_lazy --config /etc/npm-lazy-config.js"). ]
I created the service with manifold, I added all the directories to the envvar section in my created service.xml I got from
echo $PATH
but It seems the "path" dependency for nodejs can't be found.
Please help.
It looks like npm_lazy is assuming that the HOME environment variable will be set, but it's not set in the SMF. You can set that by adding it to the envvar section of the XML manifest.

How to set environment variables to get forever run meteorjs

How do you set the environment variables to get forever run meteorjs?
If I do an export and run forever, like so
export PORT=80 MONGO_URL=mongodb://localhost:3002/appname
sudo forever -f start bundle/main.js
forever will not run the meteorjs bundle with node:
/Users/../bundle/server/server.js:166
throw new Error("MONGO_URL must be set in environment");
^
Error: MONGO_URL must be set in environment
at run (/Users/../bundle/server/server.js:166:11)
at Object.<anonymous> (/Users/../bundle/server/server.js:331:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/../bundle/main.js:1:63)
at Module._compile (module.js:456:26)
error: Forever detected script exited with code: 8
If I run it directly, it runs smoothly:
sudo PORT=80 MONGO_URL=mongodb://localhost:3002/appname ROOT_URL=http://myapp.com node bundle/main.js
If I do it like in this answer it works. But why doesn't it work with the export statement?
Is there a way to tell forever a config file to read those settings? I don't see a way in the forever docs.
You can run forever just like node. Try following
sudo PORT=80 MONGO_URL=mongodb://localhost:3002/appname ROOT_URL=http://myapp.com forever -f start bundle/main.js

Resources