javascript - Deploying First Express.js App, Someone please tell me how bad my server logic is -
i deploy first express.js app , need tell me if messing up.
i running ubuntu ec2 using nginx proxy port 80 requests socket node.js app listening on.
to start app, using pm2. when wrote server app, included node.js cluster module fork , cluster needed. deployment time, see pm2 offers clustering.
here server pm2 running on production server:
confus.at('development', () => { spawnworker() }) confus.at('production', () => { if(cluster.ismaster) { master() } if(cluster.isworker) { spawnworker() } }) function spawnworker() { const port = app.settings.server.port app.server = http.createserver(app) app.server.listen(port, () => { utils.success(util.format('[+] listening on %d', port)) }) } function master() { lodash.foreach(os.cpus(), () => { cluster.fork() }) cluster.on('fork', (worker) => { utils.success('[+] forked worker', worker.id) }) cluster.on('exit', (worker) => { utils.success('[-] exited worker', worker.id) }) }
please note in spawnworker
function, app
express app created through usual const express = require('express'), app = express()
here questions:
- in above code production node.js server, doing inherently flawed?
- for express production app ran through pm2, should remove cluster logic above code , use pm2's clustering?
versions
node v5.5.0
nginx v1.4.6
pm2 1.0.0
Comments
Post a Comment