Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 获取运行在OS X上的节点以响应HTTPS连接_Node.js_Https - Fatal编程技术网

Node.js 获取运行在OS X上的节点以响应HTTPS连接

Node.js 获取运行在OS X上的节点以响应HTTPS连接,node.js,https,Node.js,Https,我有一个小节点程序 console.log("Program Started"); var http = require('http'); //Configure our HTTP server to respond with Hello World to all requests. var server = http.createServer(function (request, response) { console.log("Processing Request fo

我有一个小节点程序

console.log("Program Started");
var http = require('http');

//Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {      
    console.log("Processing Request for URL" + request.url);
    response.writeHead(200, {"Content-Type": "text/html"});
    response.end("Hello World \n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000); 
console.log("Program Ended");    
如果我在MacBook上运行此程序并访问以下URL,我会看到我的Hello World消息

http://localhost:8000/
但是,我希望这个URL也能响应HTTPS连接

https://localhost:8000/
如何使用NodeJS实现这一点


本机
http
库可以为我这样做吗?或者我需要快递

是的,您只需通过https模块:

1您将必须创建证书,您可以在这里为macOS使用此自动证书