Skip to content

Instantly share code, notes, and snippets.

Avatar

Robin Glen thearegee

  • YOOX NET-A-PORTER
View GitHub Profile
@thearegee
thearegee / hello-world-node-fastify-clustered.js
Created Sep 16, 2018
Simple hello world in Node, using Fastify and clustering for Medium post
View hello-world-node-fastify-clustered.js
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const fastify = require('fastify')();
const port = 8123;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
@thearegee
thearegee / hello-world-node-fastify.js
Created Sep 16, 2018
Simple hello world in Node, using Fastify for Medium post
View hello-world-node-fastify.js
const fastify = require('fastify')();
const port = 8123;
fastify.get('*', (req, res) => {
res.send('Hello World');
});
fastify.listen(port, () => {
console.log(`Fastify "Hello World" listening on port ${port}`);
});
@thearegee
thearegee / hello-world-node-native.js
Last active Sep 13, 2018
Simple hello world in Node, using native HTTP for Medium post
View hello-world-node-native.js
const http = require('http');
const port = 8123;
const server = http.createServer((req, res) => {
res.write('Hello World');
res.end();
});
server.listen(port, () => {
console.log(`HTTP "Hello World" listening on port ${port}`);
@thearegee
thearegee / hello-world.go
Created Sep 13, 2018
Simple hello world in Go for Medium post
View hello-world.go
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
You can’t perform that action at this time.