[NPM] 프론트엔드 개발환경의 이해 NPM - 1

인프런 - 프론트엔드 개발환경의 이해


NPM 프로젝트 생성



node.js

개발환경을 이해하고 설정


(1) 프론트엔드 개발에 Node.js 가 필요한 이유



(2) Node.js 설치



설치확인은 터미널에서 node를 입력하면 노드 터미널도구 REPL 이 실행된다.
자바스크립트 코드를 입력하고 즉시 결과를 확인할 수 있는 프로그램이다.
버전은 node --version으로 확인할 수 있다.


터미널에 npm을 입력하면
npm의 command가 나오고 프로그램이 종료된다.

Usage: npm <command>
where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    C:\Users\peace\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.13.4 C:\Program Files\nodejs\node_modules\npm


(3) 프로젝트 생성


node.js 이용해 프로젝트 개발 프로젝트를 만들어본다.


package.json 파일 내부 확인

 {
  "name": "frontend",  //프로젝트 이름
  "version": "1.0.0",  //버전정보
  "description": "",   // 설명
  "main": "index.js",  // node.js에서 사용
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
    // 프로젝트를 자동화할 수 있는 쉘 스크립트를 입력하는 곳
  },
  "author": "", //프로젝트 작성자
  "license": "ISC"  //라이센스 정보
}


(4) 프로젝트 명령어


scripts 부분의 test는
"test": "echo \"Error: no test specified\" && exit 1"
echo를 이용해 Error~~ 문장을 출력하고, 에러코드 1번을 반환한다.


터미널에 npm test를 입력하면 echo 명령어로 해당 문장이 출력되고 1번 에러코드에 맞는 메시지가 출력된다.


npm은 테스트 외에도 다양한 스크립트 명령어를 가지고 있다.

보통 test, start, install 을 많이 사용한다.
커맨드 추가는 "scripts"에 직접 추가할 수 있고
터미널에 npm run 추가한 커맨드 를 입력해서 사용할 수 있다.



Made with by Álvaro