读取文件和将字符串推入缓冲区有什么区别? -节点

时间:2018-07-09 12:54:28

标签: node.js fs

我正在尝试在节点应用程序中使用SSL证书来连接数据库。当我将SSL证书放入文件并像这样读取/使用它时,我可以连接:

fs.readFile('./cert', (err, caCert) => {
    const rethink = createRethink({
        servers: [{ host, port }],
        db,
        authKey,
        ssl: { 
            ca: caCert
        } 
    });
    rethink.dbList().run().then(result => console.log(result));
});

因此,我使用fs读取了证书,并且返回的数据可以由我的数据库库使用。

当我尝试像这样食用时

const rethink = createRethink({
    servers: [{ host, port }],
    db,
    authKey,
    ssl: { 
        ca: new Buffer(caCert, 'utf8')
    } 
});

rethink.dbList().run().then(result => console.log(result));

我收到此错误

Error: unable to verify the first certificate
    at TLSSocket.<anonymous> (_tls_wrap.js:1103:38)
    at emitNone (events.js:106:13)
    at TLSSocket.emit (events.js:208:7)
    at TLSSocket._finishInit (_tls_wrap.js:637:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:467:38)

我也尝试了base64而不是utf8,但这没用。 Bufferfs读入的内容有什么区别?我在这里想念什么?

0 个答案:

没有答案