Node.js HTTPS server with self-signed certificate creation on openssl 0.9.8zh with node.js 7.10.0

I couldn’t find a concise guide to setting this up quickly so thought it was worth a post. To quickly get something working and create a https server using the above versions of openssl and node.js, do the following:

 Generate self-signed server certificate with no password

sudo openssl req -x509 -newkey rsa:2048 -keyout ./csr.pem -out server.crt -days 3001 -nodes

Use this node.js code to setup a server quickly

const https = require('https');
const fs = require('fs');

const options = {
key: fs.readFileSync('csr.pem'),
cert: fs.readFileSync('server.crt')
};

https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(8000);

Go to https://localhost:8000 and accept the certificate, you should see ‘hello world’

The Haiku Machine

550px-Write-a-Haiku-Poem-Intro

I found this awesome cut-up poetry generator, which takes the text of famous poets and builds structured poetry out of it. The guy that made it even developed the underlying algorithm as a research project. I have put a version of a free Amazon EC2 instance, wrote a little twitter bot in node.js, and wired the poetry generator with the twitter bot, and now I have this: https://twitter.com/haikumachine – a twitter bot that posts a haiku every five minutes, derived from Dylan Thomas’s poetry.

It could be improved, and there are sometimes erroneous tweets where the syllables aren’t counted quite right, or some of the punctuation doesn’t make sense once cut up, but damnit, it’s a bot that writes Haikus.

//platform.twitter.com/widgets.js