Skip to content

Clustering with Pm2 and HapiJS #330

@ThiagoMiranda

Description

@ThiagoMiranda

Hello..
I don't know if this is the right place to question these but since it's a popular repository probably someone here encounter this very issue of mine.

Basically I've turned the app into a Hapijs app using the HapiJS webpack plugin. It's a very straightforward plugin and I use it like this:

/** Register plugin and start server **/
let hapiPlugins = [{
		register: HapiSwagger,
		options: swaggerOptions
	},{
		register: Inert
	},{
		register: Vision
	},{
		register: WebpackPlugin,
		options: './webpack.config.js'
	},
	AuthCookie,
	Bell
];

let webpackPlugin = {};

/** Register plugin and start server **/
server.register(hapiPlugins);

So I've deployed my app in an ElasticBeanstalk t2.small machine using pm2 to run it:

"copy": "copyfiles -f ./src/favicon.ico ./dist"
"dist": "npm run copy & NODE_ENV=production ./node_modules/.bin/pm2 start bootstrap.js "

It's working very well ( it's a small app used internally at my company ) but I'm not sure if it's the best approach. Digging a little into pm2 I've discovered the option to cluster my application using the -i maxoption. I've putted it and it worked. But each child process built the same webpack files before launch so I have a peak on my processing and memory having, for example in my machine, 8 "webpack compile processes" running at the same time. Using pm2 I can tell which child is the master one so this is my question:

Is there any way to just run the webpack compiling process once? Basically all that I need is to get the files from the dist/folder independently of whom putted it there. Or am I doing a totally wrong approach?

Thanks for the attention,
Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions