You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Warning:** Upon installation a private key and a self signed
@@ -21,36 +23,38 @@ this secure in any way. I suggest only using this for testing and
21
23
development where you just need an easy and quick way to run an HTTPS
22
24
server with Node.js.
23
25
26
+
> **Note**: for Node.js 24 and above, the key size has been increased to 2048 bits due to changes in OpenSSL. For earlier versions, the default key size is used.
27
+
24
28
## Example Usage
25
29
26
30
```js
27
-
var https =require('https')
28
-
var pem =require('https-pem')
31
+
consthttps=require('https');
32
+
constpem=require('@metcoder95/https-pem');
29
33
30
-
var server =https.createServer(pem, function (req, res) {
31
-
res.end('This is servered over HTTPS')
32
-
})
34
+
constserver=https.createServer(pem, function (req, res) {
35
+
res.end('This is servered over HTTPS');
36
+
});
33
37
34
38
server.listen(443, function () {
35
-
console.log('The server is running on https://localhost')
36
-
})
39
+
console.log('The server is running on https://localhost');
40
+
});
37
41
```
38
42
39
43
### Connecting
40
44
41
45
When connecting to an HTTPS server from Node.js that uses a self-signed
42
46
certificate, `https.request` will normally emit an `error` and refuse to
43
-
complete the reuqest. To get around that simply set the
47
+
complete the request. To get around that simply set the
44
48
`rejectUnauthorized` option to `false`:
45
49
46
50
```js
47
-
var opts = { rejectUnauthorized:false }
51
+
constopts= { rejectUnauthorized:false };
48
52
49
-
var req =https.request(opts, function (res) {
53
+
constreq=https.request(opts, function (res) {
50
54
// ...
51
-
})
55
+
});
52
56
53
-
req.end()
57
+
req.end();
54
58
```
55
59
56
60
If using `curl` to connect to a Node.js HTTPS server using a
@@ -65,13 +69,35 @@ curl -k https://localhost:443
65
69
The `https-pem` module simply exposes an object with two properties:
66
70
`key` and `cert`.
67
71
72
+
### `pem.generate()`
73
+
74
+
Generates a new self-signed certificate and key pair.
75
+
76
+
```js
77
+
constpem=require('@metcoder95/https-pem');
78
+
pem.generate();
79
+
```
80
+
81
+
#### Parameters
82
+
83
+
-`HttpPEMGeneratorOptions`: An object that can be passed to the `selfsigned.generate` method. This allows you to customize the generation of the key and certificate, such as setting the key size or adding custom attributes.
84
+
-`attr`: (optional) An array of attributes to include in the certificate. See the [selfsigned](https://github.com/jfromaniello/selfsigned#attributes) documentation for more information.
85
+
-`opts`: (optional) An object with options for the `selfsigned.generate` method. See the [selfsigned](https://github.com/jfromaniello/selfsigned#attributes) documentation for available options.
86
+
-`done`: (optional) A callback function that will be called with the generated key and certificate. If not provided, the function will return a promise that resolves with the generated key and certificate.
87
+
88
+
#### Returns
89
+
90
+
- HttpsPEMGenerateResult: An object containing the generated key and certificate.
91
+
-`key`: The generated private key in PEM format.
92
+
-`cert`: The generated self-signed certificate in PEM format.
0 commit comments