Created
September 16, 2018 16:34
-
-
Save robinglen/3eea038b9f0c5e94de73f3c3482fa732 to your computer and use it in GitHub Desktop.
Simple hello world in Node, using Fastify and clustering for Medium post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| cluster.on('exit', worker => { | |
| console.log(`Worker ${worker.process.pid} died`); | |
| }); | |
| } else { | |
| fastify.get('*', (req, res) => { | |
| res.send('Hello World'); | |
| }); | |
| fastify.listen(port, () => { | |
| console.log(`Fastify "Hello World" listening on port ${port}, PID: ${process.pid}`); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@thearegee
Thanks again for detailed explanation .
to answer your question.
I currently dont have any infra setup I was researching
what is best to deploy , maintain and scale a normal b2b nodejs postgres platform and this gist came across :)
here is my nodejs postgres platform
https://github.com/matt212/Nodejs_Postgresql_VanillaJS_Fastify
i would look into docker and K8 as you have stated earlier thanks for that
that being said , Any suggestion pointers to scale the boilerplate platform is welcome :)