Azure-docs: cosmos node js error running emulator sample

Created on 25 Jun 2020  Â·  11Comments  Â·  Source: MicrosoftDocs/azure-docs

Completed with error {"message":"request to https://localhost:8081/ failed, reason: self signed certificate","type":"system","errno":"DEPTH_ZERO_SELF_SIGNED_CERT","code":"DEPTH_ZERO_SELF_SIGNED_CERT","headers":{"x-ms-throttle-retry-count":0,"x-ms-throttle-retry-wait-time-ms":0}}
Press any key to exit
[Enter feedback here]


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 assigned-to-author cosmos-dsvc cosmosdb-sqsubsvc doc-bug triaged

Most helpful comment

I see same error when trying to run sample nodejs app with cosmos in backend. i changed package.json.
"start": "NODE_TLS_REJECT_UNAUTHORIZED=0 node app.js"
but when i run npm start , it throws error
'NODE_TLS_REJECT_UNAUTHORIZED' is not recognized as an internal or external command,
operable program or batch file.

All 11 comments

@nselewa Thank you for making us aware of this issue. Let me step through the Quickstart using the Cosmos DB Emulator and identify any updates to the document that may mitigate this issue. What version of the Cosmos Emulator do you currently have installed?

Latest, installed it this morning

Sent from my iPhone

Since this document offers both the SQL API Cosmos DB service or the Cosmos DB Emulator as options for this Quickstart, there should be more explicit information about running a Node.js solution with the Emulator. The Emulator document does mention how to export certificate and use for Java development with the emulator. For Node.js, the the SDK is supposed to disable TLS when used with Emulator...but the solution is throwing a self-signed certificate error. Not sure if this was introduced in v2.11.1 of the Emulator or if the Node.js application needs a more elegant way to handle this condition of self-signed certificates.

When connecting to the emulator from Python and Node.js SDKs, TLS verification is disabled.

miubezzi@ARZagato36 MINGW64 ~/projects/git-samples/azure-cosmos-db-sql-api-nodejs-getting-started (master)
$ node app.js
(node:17896) UnhandledPromiseRejectionWarning: FetchError: request to https://localhost:8081/ failed, reason: self signed certificate
at ClientRequest. (C:Usersmiubezziprojectsgit-samplesazure-cosmos-db-sql-api-nodejs-getting-startednode_modulesnode-fetchlibindex.js:1455:11)
at ClientRequest.emit (events.js:189:13)
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:17896) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17896) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This is being assigned to the content team for review.
Regards,
Mike

@burkeholland You have helped with this Quickstart doc, can you please look into this issue?

A quick and easy way to handle this is: ["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; but perhaps there is an issue with the SDK or the Emulator.

@nselewa - Could you modify the start script in the package.json to the following...

"start": NODE_TLS_REJECT_UNAUTHORIZED=0 node app.js

Let us know if that fixes the issue.

@Mike-Ubezzi-MSFT the user didn't get back to us. Do you think you can quickly test this out with the fix suggested above? Look like you already have the setup ready. If it fixes then I will update the sample. If not we need to report it to the SDK team.

@SnehaGunda I can step through this to reproduce it as I have not at this point but I was reading that the Node.js SDK for Cosmos is supposed to suppress this certificate error when connecting to the Emulator. Not sure if it is a bug with the SDK...

I have updated the code to include the "start": NODE_TLS_REJECT_UNAUTHORIZED=0 node app.js statement. We will now close this issue.

please-close

I see same error when trying to run sample nodejs app with cosmos in backend. i changed package.json.
"start": "NODE_TLS_REJECT_UNAUTHORIZED=0 node app.js"
but when i run npm start , it throws error
'NODE_TLS_REJECT_UNAUTHORIZED' is not recognized as an internal or external command,
operable program or batch file.

it appears that the latest Emulator Downloaded NodeJS Sample again contains

"start": "node app.js"

and below line doesn't work either .
"start": "NODE_TLS_REJECT_UNAUTHORIZED=0 node app.js"

So only option left is to set an Environment Variable as NODE_TLS_REJECT_UNAUTHORIZED=0 and then run the program again.

set NODE_TLS_REJECT_UNAUTHORIZED=0
npm start

I have downloaded latest Emulator this morning Explorer Version = 86609ee76ea51308f120eb150612c0f07fbba7e8

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ianpowell2017 picture ianpowell2017  Â·  3Comments

AronT-TLV picture AronT-TLV  Â·  3Comments

bityob picture bityob  Â·  3Comments

Ponant picture Ponant  Â·  3Comments

jharbieh picture jharbieh  Â·  3Comments