Skip to content

Commit 8216eeb

Browse files
apal21ZYSzys
authored andcommitted
Update how-to-create-a-HTTPS-server.md (#2203)
In accordance with issue #1977, I have updated the Article how-to-access-query-string-parameters with the following changes: 1. Used const instead of var. 2. Removed unnecessary server variable. 3. Added a note on how to execute the program.
1 parent 4c47e8b commit 8216eeb

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

locale/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ To generate a self-signed certificate, run the following in your shell:
2323
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
2424
rm csr.pem
2525

26-
This should leave you with two files, `cert.pem` (the certificate) and `key.pem` (the private key). This is all you need for a SSL connection. So now you set up a quick hello world example (the biggest difference between https and [http](/how-do-i-create-a-http-server) is the `options` parameter):
26+
This should leave you with two files, `cert.pem` (the certificate) and `key.pem` (the private key). Put these files in the same directory as your Node.js server file. This is all you need for a SSL connection. So now you set up a quick hello world example (the biggest difference between https and [http](/how-do-i-create-a-http-server) is the `options` parameter):
2727

28-
var https = require('https');
29-
var fs = require('fs');
28+
const https = require('https');
29+
const fs = require('fs');
3030

31-
var options = {
31+
const options = {
3232
key: fs.readFileSync('key.pem'),
3333
cert: fs.readFileSync('cert.pem')
3434
};
3535

36-
var a = https.createServer(options, function (req, res) {
36+
https.createServer(options, function (req, res) {
3737
res.writeHead(200);
3838
res.end("hello world\n");
3939
}).listen(8000);
4040

4141
NODE PRO TIP: Note `fs.readFileSync` - unlike `fs.readFile`, `fs.readFileSync` will block the entire process until it completes. In situations like this - loading vital configuration data - the `sync` functions are okay. In a busy server, however, using a synchronous function during a request will force the server to deal with the requests one by one!
4242

43+
> To start your https server, run `node app.js` (here, app.js is name of the file) on the terminal.
44+
4345
Now that your server is set up and started, you should be able to get the file with curl:
4446

4547
curl -k https://localhost:8000

0 commit comments

Comments
 (0)