M220JS problem in connecting

D:\mflix-js>npm start

> server@1.0.0 start
> nodemon -L ./index.js

[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./index.js`
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '@babel/register'
Require stack:
- D:\mflix-js\index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (D:\mflix-js\index.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'D:\\mflix-js\\index.js' ]
}
[nodemon] app crashed - waiting for file changes before starting...
Terminate batch job (Y/N)? y

D:\mflix-js>npm test -t db-connection

> server@1.0.0 test
> jest --passWithNoTests "db-connection"

MFLIX_DB_URI=mongodb+srv://m220student:m220password@

is this correct

D:\mflix-js>npm test -t db-connection

> server@1.0.0 test
> jest --passWithNoTests "db-connection"

'jest' is not recognized as an internal or external command,
operable program or batch file.
D:\mflix-js>npm start

> server@1.0.0 start
> nodemon -L ./index.js

[nodemon] 2.0.19
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./index.js`
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '@babel/register'
Require stack:
- D:\mflix-js\index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (D:\mflix-js\index.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'D:\\mflix-js\\index.js' ]
}
[nodemon] app crashed - waiting for file changes before starting...
1 Like
C:\Users\user>cd Desktop

C:\Users\user\Desktop>cd mflix-js

C:\Users\user\Desktop\mflix-js>npm install
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm WARN deprecated ini@1.3.5: Please update to ini >=1.3.6 to avoid a prototype pollution issue
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated request-promise-native@1.0.7: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.3: this library is no longer supported
npm WARN deprecated libnpmconfig@1.2.1: This module is not used anymore. npm config is parsed by npm itself and by @npmcli/config
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated source-map-url@0.4.0: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated node-fetch-npm@2.0.2: This module is not used anymore, npm uses minipass-fetch for its fetch implementation now
npm WARN deprecated samsam@1.3.0: This package has been deprecated in favour of @sinonjs/samsam
npm WARN deprecated babel-eslint@9.0.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
npm WARN deprecated uuid@3.3.3: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.0: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated source-map-resolve@0.5.2: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated bson@1.1.1: Fixed a critical issue with BSON serialization documented in CVE-2019-2391, see https://bit.ly/2KcpXdo for more details
npm WARN deprecated core-js@2.6.9: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated core-js@3.2.1: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path C:\Users\user\Desktop\mflix-js\node_modules\weak-napi
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.0.0
npm ERR! gyp info using node@16.15.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.0 found at "C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:16
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:406:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\user\Desktop\mflix-js\node_modules\weak-napi
npm ERR! gyp ERR! node -v v16.15.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Local\npm-cache\_logs\2022-09-25T17_30_30_821Z-debug-0.log

C:\Users\user\Desktop\mflix-js>
1 Like

I am getting these errors too. Can someone help?

server@1.0.0 test

jest --passWithNoTests db-connection

Determining test suites to run…Setup Mongo Connection
FAIL test/db-connection.test.js
● Test suite failed to run

TypeError: Cannot read properties of undefined (reading 'close')

  17 |
  18 |   async teardown() {
> 19 |     await this.global.mflixClient.close()
     |                                   ^
  20 |     await super.teardown()
  21 |   }
  22 |

  at MongoEnvironment.teardown (test/config/mongoEnvironment.js:19:35)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.063s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection

Hi @MERWIN_MATHEW, the following URI is incorrect.

Please verify your connection string, it should be of the following format:

mongodb+srv://read_only:A1PFs0tf@cluster0.k52jp.mongodb.net/sample_mflix

Learn more about Connection String in our documentation.

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

C:\Users\user\Desktop\mflix-js>npm test -t db-connection

server@1.0.0 test
jest --passWithNoTests db-connection

Determining test suites to run…Setup Mongo Connection
(node:5100) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use node --trace-warnings ... to show where the warning was created)
console.error
Something went wrong in getMovieByID: MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  312 |       // TODO Ticket: Error Handling
  313 |       // Catch the InvalidId error by string matching, and then handle it.
> 314 |       console.error(`Something went wrong in getMovieByID: ${e}`)
      |               ^
  315 |       throw e
  316 |     }
  317 |   }

  at _callee6$ (src/dao/moviesDAO.js:314:15)
  at tryCatch (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:86:17)
  at Generator._invoke (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:66:24)
  at Generator.throw (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:117:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)

console.error
Unable to convert cursor to array or problem counting documents, MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  268 |       return { moviesList, totalNumMovies }
  269 |     } catch (e) {
> 270 |       console.error(
      |               ^
  271 |         `Unable to convert cursor to array or problem counting documents, ${e}`,
  272 |       )
  273 |       return { moviesList: [], totalNumMovies: 0 }

  at Function._callee5$ (src/dao/moviesDAO.js:270:15)
  at tryCatch (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:86:17)
  at Generator._invoke (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:66:24)
  at Generator.throw (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:117:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)

FAIL test/db-connection.test.js (5.329s)
Connection
× Can access MFlix data (436ms)
× Can retrieve a movie by id (255ms)
× Can retrieve first page of movies (348ms)

● Connection › Can access MFlix data

MongoError: user is not allowed to do action [listCollections] on [sample_mflix.]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:453:61)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:456:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:625:15)

● Connection › Can retrieve a movie by id

MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:453:61)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:456:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:625:15)

● Connection › Can retrieve first page of movies

expect(received).toEqual(expected) // deep equality

Expected: 20
Received: 0

  26 |       totalNumMovies: numMovies,
  27 |     } = await MoviesDAO.getMovies()
> 28 |     expect(firstPage.length).toEqual(20)
     |                              ^
  29 |     expect(numMovies).toEqual(23530)
  30 |   })
  31 | })

  at _callee4$ (test/db-connection.test.js:28:30)
  at tryCatch (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:86:17)
  at Generator._invoke (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:66:24)
  at Generator.next (node_modules/@babel/runtime/helpers/regeneratorRuntime.js:117:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)

Test Suites: 1 failed, 1 total
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: 6.765s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection

i corrected my connecting string
now above error is showing

is there anything to do other than connecting?

now my problem is solved :blush: