Skip to content

Commit ab2e5f5

Browse files
committed
merged README from konsumer branch
1 parent 979e8e3 commit ab2e5f5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,39 @@ Install with npm
1111

1212
npm install pem
1313

14+
## Examples
15+
16+
Here are some examples for creating an SSL key/cert on the fly, and running an HTTPS server on port 443. 443 is the standard HTTPS port, but requires root permissions on most systems. To get around this, you could use a higher port number, like 4300, and use https://localhost:4300 to access your server.
17+
18+
### Basic https
19+
```javascript
20+
var https = require('https'),
21+
pem = require('pem');
22+
23+
pem.createCertificate({days:1, selfSigned:true}, function(err, keys){
24+
https.createServer({key: keys.serviceKey, cert: keys.certificate}, function(req, res){
25+
res.end("o hai!")
26+
}).listen(443);
27+
});
28+
```
29+
30+
### Express
31+
```javascript
32+
var https = require('https'),
33+
pem = require('pem'),
34+
express = require('express');
35+
36+
pem.createCertificate({days:1, selfSigned:true}, function(err, keys){
37+
var app = express();
38+
39+
app.get('/', requireAuth, function(req, res){
40+
res.send("o hai!");
41+
});
42+
43+
https.createServer({key: keys.serviceKey, cert: keys.certificate}, app).listen(443);
44+
});
45+
```
46+
1447
## API
1548

1649
### Create a private key

0 commit comments

Comments
 (0)