모듈과 NPM(Node Package Manager)이란?
const http = require('http');//http가 모듈임
var o = require('os');//os가 모듈임
console.log(o.platform());
underscore 모듈 설치시(cmd창은 항상 관리자모드로 실행 필요)
npm init 를 치고
entry point 는 이 패키지의 첫번째 실행하는 js 파일
test command : TDD 시 테스트 명령어
git repository : 깃의 저장소 주소
실행 후 package.json 파일이 생성된다. 이것을 이용해서 다른 사람들이 이 패키지를 설치할 수 있게 된다.
npm install underscore를 치면
node_modules 폴더가 생긴다.
npm install underscore --save를 치면
--save를 치면 dependencies가 생겨서 이 패키지 실행
만약 error가 나면 npm cache clean 후 다시 해보면 설치됨
이것을 치면 dependencies에 underscore가 생김
package.JSON이란 파일만 있으면 언제든지 underscore 모듈을 포함 시킬 수 있다는 의미(일종의 include <stdio.h>)
예제 실습
underscore.js
var _ = require('underscore');
var arr = [3, 6, 9, 1, 12];
console.log(arr[0]);
console.log(_.first(arr));//첫번째 원소를 리턴함
console.log(arr[arr.length-1]);
console.log(_.last(arr));//위와 같은 역할을 함
실행 결과
출처 : 생활코딩 (https://opentutorials.org/course/2136)
'프로그래밍 > Node.js' 카테고리의 다른 글
Node.js 생활코딩 정리 – Express 프레임워크 동적방식과 정적방식 차이 (0) | 2016.11.21 |
---|---|
Node.js 생활코딩 정리 – Express 프레임워크 정적 파일을 서비스하는 법 (0) | 2016.11.21 |
Node.js 생활코딩 정리 – Express 프레임워크 도입 (0) | 2016.11.21 |
Node.js 생활코딩 정리 – 동기와 비동기 프로그래밍 이란? (0) | 2016.11.21 |
Node.js - node.js에서 c/c++ 라이브러리 이용하기 (펌자료) (0) | 2015.01.17 |
Node.js - Node inspector를 통한 디버깅 방법 (0) | 2015.01.17 |
Node.js - socket.io api 간단 설명 (펌자료) (0) | 2015.01.10 |
Node.js - req.files이 동작을 안할때 - express (0) | 2015.01.06 |