node.js - Node auto reload code on https -
i'm looking tool can auto reload node.js code can run on https local development.
both forever , nodemon can reload code can't run on https.
to generate self-signed certificate, run following in shell:
openssl genrsa -out key.pem openssl req -new -key key.pem -out csr.pem openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem rm csr.pem
this should leave 2 files, cert.pem (the certificate) , key.pem (the private key). need ssl connection. set quick hello world example (the biggest difference between https , http options parameter):
var https = require('https'); var fs = require('fs'); var options = { key: fs.readfilesync('key.pem'), cert: fs.readfilesync('cert.pem') }; var = https.createserver(options, function (req, res) { res.writehead(200); res.end("hello world\n"); }).listen(8000);
node pro tip: note fs.readfilesync - unlike fs.readfile, fs.readfilesync block entire process until completes. in situations - loading vital configuration data - sync functions okay. in busy server, however, using synchronous function during request force server deal requests 1 one!
reference : https://docs.nodejitsu.com/articles/http/servers/how-to-create-a-https-server/
Comments
Post a Comment