프로그램관련 기타2020. 12. 5. 13:15

# node.js 에서 gc() 수행 방법

 

-소스코드에 추가

global.gc();

 

-node 실행

node --express_gc app.js

Posted by 차돌이라네
html52020. 9. 29. 10:50

# JSON 파일로 여러 node 동시 실행 방법

 

(1) 서버에 PM2 설치 : npm install pm2

(2) json 파일 생성하기 : play.json

{

  "apps":

  [

    {

      "name""play_1",

      "script""js/play_1.js",

      "watch"false,

      "env": {

        "NODE_ENV""production",

        "API_PORT"7000

      },

      "autorestart"true,

      "restart_delay":2000,

      "node_args": ["--max_old_space_size=4096"]

    },

    {

      "name""play_2",

      "script""js/play_2.js",

      "watch"false,

      "env": {

        "NODE_ENV""production",

        "API_PORT"7000

      },

      "autorestart"true,

      "restart_delay":2000,

      "node_args": ["--max_old_space_size=4096"]

    }

]}

 

(3) 실행 : pm2 start play.json

 

# node 특정 시간 자동 재실행

 

  (1) 사용 방법 : 위의 json 파일 생성하여 일괄 실행 파일 에  "cron_restart""0 6 * * 1" 추가

    {

      "name""play_0",

      "script""js/play_0.js",

      "watch"false,

      "env": {

        "NODE_ENV""production",

        "API_PORT"5000

      },

      "cron_restart""0 6 * * 1",

      "autorestart"true,

      "restart_delay":2000,

      "node_args": ["--max_old_space_size=4096"]

    }

 

(2) 시간 설정

-  "cron_restart""0 6 * * 1", <=== 월요일 마다  6 시 0분에 재실행

- 값 순서 : 분(0~59) , 시간(0~23), 일(1~31), 월(1~12), 요일(0~7)

 

Posted by 차돌이라네
프로그램관련 기타2017. 11. 17. 10:27


#Node.js 는 Single Thread 이다.



Posted by 차돌이라네
html52017. 11. 17. 10:16


var map1 = new Map();

map1.set('name', 'www20kr');

map1.set('date', new Date('2014-10-17'));


map1.get('name'); //'www20kr'

map1.get('date'); //Fri Oct 17 20014 09:00:00 GMT+0922 (KST);


-------------------------------------------------------------------------


var map1 = new Map();


var obj = {name : 'www20kr'};

map1.set(obj, 'Congrat');


map1.get(obj); //Congrat



-------------------------------------------------------------------------


var set1 =  new Set();


set1.add(1);

set1.add(2);

set1.add(2);


set1.size; //2

set1.has(2); // true


-------------------------------------------------------------------------


var t = (x) => x * x;


t(4);//16

t(8);//64



-------------------------------------------------------------------------

*같은 함수의 코딩 방식 차이


db.find(id, function(err, data)

{

return data;

}


//es6

db.find(id, (err, data) => data);

-------------------------------------------------------------------------


var custom = new Custom();

custom.on('event1', function()

{

console.log('event1====');

}

custom.emit('evetn1);


-------------------------------------------------------------------------








Posted by 차돌이라네