이 문제는 node.js에서 발생합니다. 응용 프로그램을 시작할 때 --trace-sync-io 노드를 사용하고 request 모듈과 request-promise 모듈을 사용하여 server.js 파일에서 api 호출을 할 때, 그것은 여전히 Sync API를 사용하고 있으며 내 request.promise 호출의 시작을 가리킨다 고 경고합니다. 내가 명령 node --trace-sync-io server.js
와 노드를 시작할 때Node.js로 비동기 api 호출을 만드는 방법은 무엇입니까?
var request = require("request");
var rp = require("request-promise");
var options = {
uri: url,
json: true
};
rp(options).then(function (data){
//then I do something with data here
}.catch(function(err){
//catch errors here
})
그래서 나는 WARNING: Detected use of sync API
및 스택 추적을 얻을 내가 통화 RP를 시작 라인을 가리키는
(node:17212) WARNING: Detected use of sync API
at rng (mypath\node_modules\uuid\lib\rng.js:7:10)
at v4 (mypath\node_modules\uuid\v4.js:13:52)
at Multipart (mypath\node_modules\request\lib\multipart.js:11:19)
at Request (mypath\node_modules\request\request.js:127:21)
at request (mypath\node_modules\request\index.js:54:10)
at mypath\server.js:333:8
at emitOne (events.js:96:13)
at emit (events.js:188:7)
at Query.handleReadyForQuery (mypath\node_modules\pg\lib\query.js:126:8)
(options.then (기능 (데이터)))
[crypto.randomBytes]의 동기화 버전을 호출하는 [this function] (https://github.com/kelektiv/node-uuid/blob/3b218806aa82e76c7aaa6c9ad62e4d5abe2de4e3/lib/rng.js#L6-L8)을 가리 킵니다. '. 'request'와'uuid'를 패치하지 않고서는 고칠 수는 없지만 실제 문제가 무엇인지는 알 수 없습니다. – robertklep
@robertklep 요청 모듈이 왜 그런 식으로 호출합니까? 내가 생각하는 문제는 동기화 API를 사용할 때 서버가 다른 것을 처리 할 수 없기 때문에 node.js와 함께 동기화 API를 사용하면 전체 사이트 속도가 느려진다는 점입니다. 그러나 나는이 특별한 것이 어떤 영향을 미치는지 모른다. – Quartal
'request'는 멀티 파트 요청을 위해이를 사용합니다 (UUID는 구분 기호로 사용됩니다), 멀티 파트 데이터를 게시하지 않을 때에도 명백하게 나타납니다. 그러나별로 중요하지 않습니다. 랩탑은 약 300K UUIDv4를 초당 생성 할 수 있기 때문에, 각각 약 3.3 마이크로 초가 걸립니다. 그것은 눈에 띄지 않을 것입니다. – robertklep