const URL = require('url').URL;
const myURL = new URL('https://example.org/foo');
console.log(myURL.href); // https://example.org/foo
console.log(myURL.protocol); // https:
console.log(myURL.hostname); // example.org
console.log(myURL.pathname); // /foo
Run Code Online (Sandbox Code Playgroud)
但是我如何获取用户向服务器发出的请求 url ???
var privateKey = fs.readFileSync('/path/to/franciskim.co.key', 'utf8');
var certificate = fs.readFileSync('/path/to/franciskim.co.crt', 'utf8');
var credentials = { key: privateKey, cert: certificate };
Run Code Online (Sandbox Code Playgroud)
为什么不只是 fs.readFile?为什么要读取文件同步?
node.js ×2