다른 버전의 nodejs 를 각각 띄우고 nginx 로 연결해서 clustering 구성
환경 구성
nodejs version manager 인 nvm 으로 2가지 버전의 node js 를 설치
nvm install v16
nvm install v14
BASH
이제 테스트용 app.js 파일 생성
var http = require('http');
var process = require('process');
var version = process.version;
var port = parseInt(process.argv.slice(2));
console.log(version + " port:" + port);
http.createServer(function (req, res) {
var index = '<html><head></head><body><h1> Hello Node Version: ' + version
+ '</h1></body></html>';
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(index);
}).listen(port);
JS
실행
$ nvm run v14 app.js 9999
Running node v14.18.1 (npm v6.14.15)
v14.18.1 port:9999
BASH
$ nvm run v16 app.js 8888
Running node v16.13.0 (npm v8.1.0)
v16.13.0 port:8888
BASH
같이 보기