简体   繁体   中英

Unable to configure MongoDB in Angular application that is using Express and Azure Cosmos DB

I am facing strange issue in configuring and using Azure CosmosDB MongoDB Api in angular application, the configuration and code is referred from https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-develop-mongodb-nodejs-part2 and https://johnpapa.net/angular-cosmosdb-1/ , though i was able to configure and run application with express when i am trying to configure and install Mongoose node module getting series of errors:

1) Cannot find module 'mongodb-extjson 2) Cannot find module 'bson-ext' 3) ENOENT: no such file or directory, access 'XXX\node_modules\bson-ext\lib\package.json

I have tried re installing packages but no success.

I am using Angular version 10 with mongoose version 5.11.14 i am getting error at compile time when trying to run it from vs code and trying to launch server/index.js on port 3000.

Your help is greatly appriciated.

You are getting 1 and 2 because the MongoDB driver checks for optional requirements during initialization. You can F5 past them in VS Code. Or install them like so:

node install mongodb-extjson
node install bson-ext

Number 3 is also due to an exception during startup. I have no clue to why this is missing but if you want to skip initial throws in the debugger you can start without debugging first and then "attach" to it. Like so:

node --inspect --nolazy server/index.js

To attach to node with VSCode, make sure you have something like this in your.vscode\launch.json:

{
    "name": "Docker: Attach to Node",
    "type": "node",
    "request": "attach",
    "port": 9229,
    "address": "localhost",
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/",
    "protocol": "inspector"
 }

Many node modules test things at startup by throwing and catching. For example:

var hasStacks = false;
try {
    throw new Error();
} catch (e) {
    hasStacks = !!e.stack;
}

...and this leads to break in VS Code debugger. So you might want to attach (ie press run "Docker: Attach to Node" after a few seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM