1

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...

Praney Pareek
  • 49
  • 1
  • 5

1 Answers1

0

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

Praney Pareek
  • 49
  • 1
  • 5