Modul HTTPS Node.js
Contoh
Buat server https yang mendengarkan pada port 8080 komputer Anda.
Ketika port 8080 sudah diakses, tulis "Hello World!" kembali sebagai tanggapan:
var https = require('https');
https.createServer(function (req, res)
{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
}).listen(8080);
Definisi dan Penggunaan
Modul HTTPS menyediakan cara membuat Node.js mentransfer data melalui protokol HTTP TLS/SSL, yang merupakan protokol HTTP aman.
Sintaksis
Sintaks untuk menyertakan modul HTTPS dalam aplikasi Anda:
var https = require('https');
Properti dan Metode HTTPS
Method | Description |
---|---|
createServer() | Creates an HTTPS server |
get() | Sets the method to GET, and returns an object containing the user's request |
globalAgent | Returns the HTTPS Agent |
request | Makes a request to a secure web server |