Winston의 Log Format을 Customizing 하는 방법에 대해 알아본다.


Winston Log Format을 수정하기 위해서는 Winston Transport의 formatter 설정을 구현해야 한다.

  • timestamp 및 output format 함수를 재구현
function _timestamp() {
        return moment().format("YYYY-MM-DD HH:mm:ss.SSS");
}
function _customFormatter(options) {
    return options.timestamp() +
            ' ['+ options.level.toUpperCase() + ']' +
            '['+ options.meta.loggerName + '] ' +
            (!options.meta.clientMessage ? options.message : options.meta.clientMessage);
}
var consoleAppender = new winston.transports.Console({
    timestamp: _timestamp,
    formatter: _customFormatter
});
var fileAppender = new winston.transports.File({
    timestamp: _timestamp,
    formatter: _customFormatter,
    json: false,
    filename: 'filelog.log'
});


Posted by leechwin
,

nodejs 설치후 $ node app.js 등과 같이 app을 실행시킬때 다음과 같은 에러가 발생하는 경우가 있다.

  •  /usr/bin/env: node: No such file or directory

원인은 node 명령이 등록이 되지않아서 인데, 실제로 nodejs 라는 명령으로 실행하면 실행이 된다.


이때는 다음과 같이 nodejs의 심볼릭 링크를 만들어 주면 된다.

  • $ ln -s /usr/bin/nodejs /usr/local/bin/node

이후 $ node app.js 명령이 실행이 된다.


참고: https://github.com/nodejs/node-v0.x-archive/issues/3911

'Node.js' 카테고리의 다른 글

[Node.js][Winston] Log File Managment  (0) 2017.02.03
[Node.js][Winston] Custom Log Format  (0) 2017.02.03
[Node.js] NVM을 통한 nodejs 설치  (0) 2016.12.21
[BOWER] Proxy 설정  (0) 2016.12.16
[NPM] Proxy 설정  (1) 2016.12.16
Posted by leechwin
,

NVM(Node Version Manager)를 통한 nodejs 설치에 대해 알아보자.


NVM을 통하여 기존 설치된 node.js 버전을 변경하는 동작도 가능하다.


다음 명령을 통해 NVM을 설치한다.

  • $ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

설치된 NVM 버전은 다음 명령을 통해 확인 가능하다.

  • $ nvm --version
  • 0.32.1

NVM 설치가 잘 안되면 아래 명령으로 개발에 필요한 기본 패키지를 설치한다.

  • $ apt-get install build-essential libssl-dev


NVM 설치가 끝나면 다음과 같이 원하는 버전의 nodejs를 설치한다.

  • $ nvm install v12.18.2

$ nvm install v12.18.2

Downloading and installing node v12.18.2...

Downloading https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz...

######################################################################## 100.0%

Computing checksum with sha256sum

Checksums matched!

Now using node v12.18.2 (npm v6.14.5)


NVM을 통해 nodejs가 설치되면서 npm도 같이 설치가 된다.

  • $ npm -v
  • 3.10.8

현재 설치된 nodejs 버전은 다음 명령으로 확인가능하다.

  • $ nvm ls

$ nvm ls

       v10.17.0

->     v12.18.2

default -> v10.17.0

node -> stable (-> v12.18.2) (default)

stable -> 12.18 (-> v12.18.2) (default)

iojs -> N/A (default)

lts/* -> lts/erbium (-> v12.18.2)

lts/argon -> v4.9.1 (-> N/A)

lts/boron -> v6.17.1 (-> N/A)

lts/carbon -> v8.17.0 (-> N/A)

lts/dubnium -> v10.21.0 (-> N/A)

lts/erbium -> v12.18.2

 


현재 사용중인 nodejs 버전은 다음 명령으로 확인가능하다.

  • $ nvm current
  • v12.18.2
기본 nodejs 버전을 설정하려면 다음 명령으로 변경가능하다.
  • $ nvm alias default v12.18.2
  • default -> v12.18.2


Posted by leechwin
,

[BOWER] Proxy 설정

Node.js 2016. 12. 16. 11:01

bower install 실행시에 Proxy 환경일 경우 제대로 설치가 안되는 경우가 있다.


이때에는 bower.json 파일이나 .bowerrc 파일에 Proxy 설정이 필요하다.


예제

  • {
      "proxy": "http://yourProxy:yourPort",
      "https-proxy": "http://yourProxy:yourPort",
      "strict-ssl": false,
      "directory": "bower_components",
      "registry":"http://bower.herokuapp.com"
    }
만약 bower install 명력이 동작안하는 경우 bower.json 파일을 .bowerrc 로 변경해서 bower install 을 수행하여 본다.

bower.json 은 최신 bower버전에서 도입되어 구버전의 bower일 경우 인식안되는 경우가 있다.


Posted by leechwin
,

[NPM] Proxy 설정

Node.js 2016. 12. 16. 10:59

npm install 실행시에 Proxy 환경일 경우 제대로 설치가 안되는 경우가 있다.


이때에는 다음과 같이 npm config 명령을 통해 Proxy 설정이 필요하다.


예제

  • npm config set proxy http://111.111.111.111:8081
  • npm config set https-proxy https://111.111.111.111:8081
  • npm config set strict-ssl false
  • npm config set registry http://registry.npmjs.org/

npm 설정값은 다음 명령으로 확인가능하다.

  • npm config list
설정된 값은 ~/.npmrc 파일에 저장되어 있다.


Posted by leechwin
,

Windows 에서 node 관련 npm 명령등을 수행시에 다음과 같이 'node-gyp' 관련 에러가 발생 하는 경우가 있다.

  • npm ERR! time@0.11.4 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the time@0.11.4 install script 'node-gyp rebuild'. npm ERR! This is most likely a problem with the time package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls time npm ERR! There is likely additional logging output above.


이것은 python 관련 환경 문제로 python 2.7과 Microsoft Visual Studio C++ 2012 Express를 설치해야한다.

설치 완료 후 다시 npm 명령을 수행하면 잘 실행이 된다.


Reference


Posted by leechwin
,