Giter Site home page Giter Site logo

npm-study's Introduction

NPM-Study

NPM Study(Saeng_hwal Coding)

뭘 배울건가

  1. 모듈을 만드는 법
  2. 명령어 환경에서 실행하는 앱을 만드는 법
  3. 나의 패키지를 NPM Registry 에 등록하는 방법
  4. NPM Registry 의 패키지를 사용하는 방법
  5. NPX를 통해서 일회용으로 패키지를 실행하는 방법

모듈 만들기

내가 만들 모듈의 소비자들에게 부품으로 사용 할 패키지를 만들어서 제공 해보자. 위와같은 작업을 하기 위해서는 '현재 디렉토리는 패키지이다' 라고 nodeJS 에게 알려줄 필요가 있다.

$ npm init -> 이게 알려주는 거임.

Press ^C at any time to quit. package name: (producer) @hoon/hi -> 패키지의 이름을 정해주는건데 그냥 hi 라고하면 당연히 이미 있는 이름이겠지 그러니 그 앞에 스코프(@hoon)라는걸 붙여주고 이 스코프는 범위를 의미하고 hoon이라는 범위안에 있는 패키지 이름인 hi 이렇게 되는거다. version: (1.0.0) 0.0.1 -> 엔터치면 저 가로안의 버전으로 만드는 것 이다. 나는 그냥 완전 초기니까 0.0.1로 내맘대로 정한거다. description: package for npm Study -> 말그대로 그냥 이 패키지가 뭔지 설명하는 부분. entry point: (index.js) main.js -> 나의 패키지를 다른사람이 부품으로 가져다 쓸 때 어떤 파일의 내용을 입구파일로해서 사용하는지 정하는것.

test command: 현재는 노상관들 그냥 지나가자 git repository: 현재는 노상관들 그냥 지나가자 keywords: 현재는 노상관들 그냥 지나가자 author: 현재는 노상관들 그냥 지나가자 license: (ISC) 현재는 노상관들 그냥 지나가자 About to write to /Users/seunghoon/Desktop/IhaveaDream/생활코딩강의/NPM/producer/package.json:

{ "name": "@hoon0123/hi", "version": "0.0.1", "description": "package for npm Study", "main": "main.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "", "license": "ISC" }

Is this OK? (yes) yes

위처럼 yes를 누르면 package.json 이라는 파일이 생기고 내가 입력했던 내용이 json의 데이터포맷으로 저장되어있는걸 볼 수 있다.

자 이제 나의 패키지의 실제 내용을 작성을 해나갈건데, 그런데 main의 이름이 'main.js' 이기 때무네 main.js라는 이름의 파일을 작성해야 한다. 그리고 인사말을 담고있는 앱을 만들려고 하니까(일단 그렇다.)

(main.js) module.exports = {ko: '앙뇽', en: 'hi'}

라고 만들어주고

우리의 패키지를 사용하는 소비자들이 쓸 수 있게 하려면 이것을 소비자들에게 export 해야한다. 그래서 module.export 해준거고 이렇게 해줌으로서 저 main.js를 required 했을 때 export 뒤쪽의 저 객체가 전달이 되는것 이다.

자 그럼 이것을 어떻게 소비자들에게 전달 할 것인지 아라보자.

NPM Registry - 패키지 업로드 하기

npmjs.com은 전세계 가장큰 소프트웨어 저장소중의 하나다. 특히나 nodeJS로 만들어진 거의 모든 프로그램들은 이곳에 저장이 되어있다. 이곳을 npm Registry 라고 한다.

이곳에 내가 만든 앱을 업로드해서 다른사람도 볼 수 있게 쓸 수 있게 해볼것이다.

일단 npmjs.com 에 가입하고,

$ npm publish --access public

위처럼 커맨드라인에 입력을 해주면 아래같은 에러가 발생한다.

npm notice npm notice 📦 @hoon/[email protected] npm notice === Tarball Contents === npm notice 3.0kB 필기
npm notice 41B main.js
npm notice 224B package.json npm notice === Tarball Details === npm notice name: @hoon/hi
npm notice version: 0.0.1
npm notice filename: @hoon/hi-0.0.1.tgz
npm notice package size: 1.8 kB
npm notice unpacked size: 3.3 kB
npm notice shasum: 7b5b3c4fb7c70138887b2ca9f15c9bcc6aa7f8b1 npm notice integrity: sha512-0RQQ+w2aGR2BB[...]zMkxicbfdt2gQ== npm notice total files: 3
npm notice npm ERR! code ENEEDAUTH npm ERR! need auth This command requires you to be logged in. npm ERR! need auth You need to authorize this machine using npm adduser

npm ERR! A complete log of this run can be found in: npm ERR! /Users/seunghoon/.npm/_logs/2022-04-28T13_30_31_034Z-debug.log

로그인 안했다 뭐 이런 애기다. 이제 이때 내가 npmjs.com에서 가입했던 아이디랑 패스워드 사용하는거다.

➜ producer npm login

npm notice Log in on https://registry.npmjs.org/ Username: hoon0123 Password: Email: (this IS public) [email protected] Enter one-time password from your authenticator app: 09378408 Logged in as hoon0123 on https://registry.npmjs.org/.

위와같은 과정을 통해 로그인을 했고

$ npm publish --access public

한번 더 해주면

npm notice npm notice 📦 @hoon0123/[email protected] npm notice === Tarball Contents === npm notice 5.1kB 필기
npm notice 41B main.js
npm notice 228B package.json npm notice === Tarball Details === npm notice name: @hoon0123/hi
npm notice version: 0.0.1
npm notice filename: @hoon0123/hi-0.0.1.tgz
npm notice package size: 2.7 kB
npm notice unpacked size: 5.4 kB
npm notice shasum: c6cbe39a2aaa20241a3f9de6ba354aefbbfb618b npm notice integrity: sha512-00a9kxQgbMItb[...]qiKtXufUaONNw== npm notice total files: 3
npm notice This operation requires a one-time password. Enter OTP: 26072584

짠 이렇게 성공적으로 업로드가 되었다. 짝짝짝

만약 내가 패키지의 내용을 수정해서 다시 업로드하려면 package.json 에서 버전을 상위버전으로 바꾼 후

$ npm publish

만 해주면 변경한 버전이 제출이 된다.

그리고 npmjs.com 에서 내 프로필클릭 후 packages 라는 항목을 들어가면 내가 만든 package @hoon0123/hi 가 있꼬 그것을 클릭하면 나의 npm package 홈페이지가 나오는것을 볼 수 있다.....와우

패키지 사용하기

그렇다면 모듈을 사용하는것은 어떻게 하나

사용하는 입장에서도 자신의 패키지로서 정의를 해야한다.

$ npm init -y

해주면 자동으로 기본값이 일단 설정이 되고 package.json 파일이 생겨난다.

그리고 이제 패키지를 설치를 해보자.

$ npm i @hoon0123/hi

설치가 완료되면 package.json에 아래처럼 내가 설치한 패키지의 이름과 버전이 만들어지고 package-lock.json 이라는 파일이 생기고 node_modules 라는 폴더가 생긴다.

{ "name": "consumer", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@hoon0123/hi": "^0.0.1" } }

그리고 node_modules 라는 디렉토리안에 우리의 @hoon0123 스코프이름인 디렉토리가 있고 그안에 패키지의 이름인 hi 가 만들어진다. 그리고 그 hi 디렉토리안에 관련된 파일들 내가 만들었던 파일들이 생기게 된거다.

자 그러면 이 패키지의 우리가 부품으로 사용할 저 패키지의 main.js 안에있는 내용을(객체가 있지 내가 만들었던) 사용을 해보자.


(index.js) const greeting = require('@hoon0123/hi');

console.log(greeting);


위처럼 index.js 파일을 만든 후 내가 만든 패키지를 불러온 뒤 $ node index.js 로 실행을 해보면 커맨드라인에

➜ consumer node index.js { ko: '앙뇽', en: 'hi' }

이런 객체를 확인할 수 있다.

자 지금은 저 간단한 객체가 들어가있지만 저 안에 어마무시한게 들어가있다고 생각하면 그것을 사용할 수 있게 되는것이다.

그리고 만약 내가 사용한 패키지의 버전을 확인하려면 $ npm outdated

를 통해 확인할 수 있다.

또한 패키지의 버전이 업데이트 되었다면

package.json의

{ "name": "consumer", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@hoon0123/hi": "0.0.1" <- 이부분의 } }

이부분의 버전을 고쳐준 뒤

$ npm update 해주면 된다.

매번 버전을 적어주기 귀찮다면

{ "name": "consumer", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@hoon0123/hi": "~0.0.1" <- 이부분의 } }

위처럼 물결표시를 해주면 2번쨰자리까지는 고정이고 맨마지막 3번째 숫자는 가장 최신버전으로 업데이트를 해주게 된다.

저 자동업데이트 되는 범위를 정하는건 semver.npmjs.com 에서 확인할 수 있따.

명령행 프로그램 만들기

완제품으로서 내가만든 패키지를 다른사람들이 쓸수있도록 공급해볼것이다. 커맨드라인에서 명령어로서 나의 패키지를 실행시키는것이다. (node_modules 폴더안에 넣어놓고 쓰는게 아니라 하나의 제품으로서 실행시키는 패키지)

일반적으로 cli.js 파일이름을 많이 사용한다.

그리고 이파일은 main.js의 내용을 가져다 쓸것이다.


(cli.js)

const greeting = require('./main');

console.log('Greeting: ', greeting.en);

(main.js) module.exports = {ko: '앙뇽', en: 'hi'}


위처럼 cli.js 에 main.js를 가져온 뒤 console.log 하게 하는 코드를 짠 후 커맨드라인에 cli.js 를 실행시키면

$ node cli.js Greeting: hi

위처럼 실행이 된다. 그런데 이건 한상 똑같은 결과만을 내놓는다. 너무 정적이다. 그렇다면 우리가

$ node cli.js ko 를 커맨드라인에 입력하면 '앙뇽' 이라고 나올 수 있게 한다면 얼마나 더 효용성이 높아니겠는가 즉, 입력기능을 넣고 싶은것이다.

그걸위해 약속된기능의 코드가 process.argv 이다. argv = argument variable


(cli.js) const greeting = require('./main'); console.log(process.argv); console.log('Greeting: ', greeting.en);

(main.js) module.exports = {ko: '앙뇽', en: 'hi'}


자 그럼 위처럼 process.argv 를 console.log 해보면 어떻게 나올까.

$ node cli.js

[ '/usr/local/bin/node', '/Users/seunghoon/Desktop/IhaveaDream/생활코딩강의/NPM/producer/cli.js' ] Greeting: hi

이와같은 배열이 나온다. 우리가 실행한 node runtime이 첫번쨰 원소 두번쨰 원소는 우리가 실행하는 프로그램이다. 그리고 세번쨰 인자부터 내가 입력하는 값이 들어 가게 된다.

$ node cli.js ko en he

[ '/usr/local/bin/node', '/Users/seunghoon/Desktop/IhaveaDream/생활코딩강의/NPM/producer/cli.js', 'ko', 'en', 'he' ] Greeting: hi

자 그럼 내가 아래처럼 process.argv[2] 를 console.log 하게되면 내가 입력한 값이 커맨드라인에 출력되게되는것이다.


(cli.js) const greeting = require('./main'); console.log(process.argv[2]); console.log('Greeting: ', greeting.en);

(main.js) module.exports = {ko: '앙뇽', en: 'hi'}


$ node cli.js ko ko Greeting: hi

자 그럼 아래처럼 console.log('Greeting: ', greeting[process.argv[2]]); 해주게되면 내가 입력하는 값에 따라 각기 다른 인사말이 나오게 되는것이다.


(cli.js) const greeting = require('./main'); console.log(process.argv[2]); console.log('Greeting: ', greeting[process.argv[2]]);

(main.js) module.exports = {ko: '앙뇽', en: 'hi'}


$ node cli.js ko ko Greeting: 앙뇽

$ node cli.js en en Greeting: hi

아니근데 이거 실행할 때 마다 앞에다가 'node' 라고 붙이는게 너무 귀찮다. 그래서 그냥 아래처럼 실행해봤더니

$ ./cli.js zsh: permission denied: ./cli.js

이렇게 거정당했다. 왤까 아래처럼 파일을 조사해 보면

$ ls -al total 56 drwxr-xr-x@ 6 seunghoon staff 192 Apr 29 21:35 . drwxr-xr-x@ 5 seunghoon staff 160 Apr 29 21:35 .. -rw-r--r-- 1 seunghoon staff 119 Apr 29 21:32 cli.js -rw-r--r-- 1 seunghoon staff 41 Apr 26 11:48 main.js -rw-r--r-- 1 seunghoon staff 228 Apr 28 23:24 package.json -rw-r--r-- 1 seunghoon staff 14151 Apr 29 21:37 필기

요렇게 뜨는데 "-rw-r--r--" 이게 뭐냐면 파일의 권한을 나타내는거다. "rw-r--r--" 딱 요 9부분이 권한을 나타내는거다. 그중 저 첫번째 3개가 소유자의 권한을 나타내는건데 3개는 read(읽기), write(수정), execute(실행) 이다. 근데 지금 rw- 로 되어있는거 보면 실행권한이 없는거고 그래서

$ ./cli.js zsh: permission denied: ./cli.js

요렇게 된거다.

자 그래서 이제 저 cli.js 를 소유자는 실행이 가능하도록 권한을 부여할것이다.

$ chmod +ux cli.js = $ change permission mode + user execute cli.js

자 이제 권한을 부여했고 다시 확인해보면

$ ls -al total 56 drwxr-xr-x@ 6 seunghoon staff 192 Apr 29 21:44 . drwxr-xr-x@ 5 seunghoon staff 160 Apr 29 21:44 .. -rwxr-xr-x 1 seunghoon staff 119 Apr 29 21:32 cli.js

짠 첫번쨰에있는 소유자 권한에 rwx 가 모두 나오는것을 확인할 수 있다.

그래서 호기롭게 다시 실행을 해보았더니

$ ./cli.js ./cli.js: line 1: syntax error near unexpected token (' ./cli.js: line 1: const greeting = require('./main');'

위와같이 에러가 뜬다. 왜일까 저 cli.js 는 nodeJS 다. 즉, javascript 인거지.

그런데 운영체제한테 그냥 야 실행시켜 하면 당연히 모르겠지 그러니 "nodeJS 로 만들어졌으니까 nodeJS Runtime 프로그램을 통해서 실행시켜야해" 라고 얘기를 해줘야한다. 그래서 저 cli.js 의 최상단에 아래처럼 적어주는것이고 저걸 적어줌으로 인해 운영체제한테 이 파일은 nodeJS에 맞게 작성한것이니 nodeJS로 실행시키라고 알려줄 수 있는것이다.


(cli.js) #!/usr/bin/env node

const greeting = require('./main'); console.log(process.argv[2]); console.log('Greeting: ', greeting[process.argv[2]]);


$ ./cli.js ko ko Greeting: 앙뇽

짠 이제 실행이 왼다.

자 이렇게해서 우리가 내용을 만들었다. 이제 다른사람이 쓸 수 있게 해볼거다.

package.json 으로 들어가서 'bin' 이라는 property를 추가한다. 그리고 그안의 프로퍼티에 내가 만든 cli.js 파일을 넣어준다.


(package.json)

{ "name": "@hoon0123/hi", "version": "0.0.1", "description": "package for npm Study", "main": "main.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "bin": { "say-hi": "./cli.js" <- 여기 넣어준겨 }, "author": "", "license": "ISC" }


이렇게 해주면 이 패키지를 설치한 사람이 say-hi 라고하면 내가만든 cli.js 파일을 실행하게 되는것이다.

자 여기까지했으니 업로드 한번 하고 넘어가자 공부헀듯이 업로드를하려면 반드시 package.json에서 버전업을 해야한다. 버전업 해주고 아래처럼 커맨드라인에 입력

$ npm publish

패키지 설치하고 실행하기


(package.json)

{ "name": "@hoon0123/hi", "version": "0.0.2", "description": "package for npm Study", "main": "main.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "bin": { "say-hi": "./cli.js" }, "author": "", "license": "ISC" }


생산자가 만든 nodeJS 패키지 지금은 cli.js 저 파일을 소비자의 컴퓨터에서 설치해서 실행하는 방법을 알아볼것이다. 패키지를 만든 생산자는 package.json 에다가 자신이만든 패키지를 사용하는 사용자들은 'say-hi 라는 명령어를 통해서 이 cli.js 를 실행할겁니다' 라고 정의를 해놓았다.

자 그러면 어떻게하면 소비자들이 저 say-hi를 통해서 cli.js 실행할 수 있을까 라는걸 지금부터 살펴보자.

사용자가 다른 패키지를 명령어로서 실행하는 방법은 크게 3가지가 있다.

  1. 자신의 로컬패키지, package.json 이라는 파일에 속해있는 패키지 거기에다가 설치하는것 <- node_modules 에 설치되어있는 것이다.
  2. 이 컴퓨터 어디에서든지 명령어를 통해서 실행시킬 수 있게 전역적으로 설치하는 방법
  3. 설치하지 않고 그냥 패키지를 다운로드받고 실행하고 삭제해서 1회성으로 실행하는 방법 <- 항상 최신버전이고 설치하는과정에서의 찌꺼기가 남지 않는다.

자 하나씩 살펴보기 위해 일단 내가 설치했던 나의 패키지를 지워보자.

$ npm uninstall @hoon0123/hi

지워주니 아래처럼 dependencies 에서 사라졌다.


(package.json) <- Consumer 단임.

{ "name": "consumer", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC" }


  1. 로컬패키지에 설치해서 사용하는 방법 -> 이미 해봤던 가장 보편적인 방법

$ npm i @hoon0123/hi

자 이렇게 설치를 하면 당연히 package.json에 아래처럼 추가가되있고


(package.json) <- Consumer 단임.

{ "name": "consumer", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@hoon0123/hi": "^0.0.2" } }


그러면 node_modules 폴더에는 어떤 변화가 생겼을까

node_modules에 .bin 이라는 디렉토리가 생겼다. 그리고 그안에 보면 say-hi 라는 파일이 생겼고

$ .bin ls -al total 0 drwxr-xr-x@ 3 seunghoon staff 96 Apr 29 22:33 . drwxr-xr-x@ 5 seunghoon staff 160 Apr 29 22:33 .. lrwxr-xr-x 1 seunghoon staff 22 Apr 29 22:33 say-hi -> ../@hoon0123/hi/cli.js

그 파일에는 내용이 없고 @hoon0123/hi/cli.js <- 여기로 링크가 걸려있다. 그래서 say-hi를 실행시키면 결국 cli.js 를 실행시키는 결과를 가지게 되는것이다.

$ consumer ./node_modules/.bin/say-hi ko ko Greeting: 앙뇽

짠 위처럼 실행하니까 결국 cli.js 가 실행된다.

자 이게 로컬에 설치해서 사용하는 방식이다.

  1. 전역영역에 설치해서 사용하는 방법

전역영역에 설치할 떄 는
$ npm i -g @hoon0123/hi = $ npm install --global @hoon0123/hi

라고 적어주면 된다. (둘다 가능이다.)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

npm install -g 전역 설치 시

아래와 같은 에러가 발생하는 경우가 있습니다.

Error: EACCES: permission denied, access '/usr/lib/node_modules' 여기서는 @vue/cli를 전역으로 설치 시 아래와 같이 에러가 발생하였습니다.

removed 1 package, and audited 1 package in 148ms

found 0 vulnerabilities ➜ consumer npm i -g @hoon0123/hi
npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/@hoon0123 npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@hoon0123' npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@hoon0123'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/usr/local/lib/node_modules/@hoon0123' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/seunghoon/.npm/_logs/2022-04-29T13_49_55_012Z-debug.log ➜ consumer npm i -g @hoon0123/hi npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/@hoon0123 npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@hoon0123' npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@hoon0123'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/usr/local/lib/node_modules/@hoon0123' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/seunghoon/.npm/_logs/2022-04-29T13_50_00_892Z-debug.log

에러 메시지에서 보여지듯이

/usr/lib/node_modules에 대한 권한이 없어서 생기는 오류 메시지 입니다.

가장 간단한 해결방법은 관리자 권한인 sudo로 설치를 하면 해결됩니다.

하지만 npm 공식 사이트에서는 npm 기본 경로를 변경해서 사용할 것을 권장합니다. 참고 : npm 사이트

해결방법 홈 디렉터리에서 전역 설치를 위한 디렉터리를 만듭니다

mkdir ~/.npm-global 새 디렉토리 경로를 사용하도록 npm 구성합니다

npm config set prefix '~/.npm-global' 텍스트 편집기에서 ~/.profile 파일을 열거나 만들고 다음 줄을 추가합니다

export PATH=~/.npm-global/bin:$PATH 시스템 변수를 업데이트합니다.

source ~/.profile 테스트하려면 sudo를 사용하지 않고 전역 적으로 패키지를 설치합니다

npm install -g @vue/cli 에러 없이 설치되는 것을 확인할 수 있습니다.

이상으로 npm 전역 설치 시 EACCES: permission denied 해결 방법이었습니다.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

자 요롷게 일단 설치를 했고 consumer 폴더 바깥으로 나가서

➜ Desktop say-hi ko ko Greeting: 앙뇽

Desktop 폴더로 가서 say-hi ko 를 실행해도 된다. 즉, 전역적으로 사용할 수 있는 커맨드라인 명령어 프로그램이 설치가 되서 세팅까지 된것이다.

  1. NPX

여기서 x 는 execute의 x 다. 즉. npx는 nodeJS 패키지를 실행할 떄 사용하는 프로그램인것이다. 이 npx의 진정한 가치는 1회용 프로그램을 실행할 떄 나타나는데 테스트 해보기 위해 일단 로컬과 전역에 있는 나의 @hoon0123/hi 패키지를 다 지워준다.

$ npm uninstall @hoon0123/hi <- 로컬영역 삭제 $ npm uninstall -g @hoon0123/hi <- 글로벌영역 삭제

자 이제 실행시켜 보자

$ npx @hoon0123/hi ko ko Greeting: 앙뇽

오 된다.

이게 뭐가 좋냐면 실행할 떄 마다 최신버전이라는것을 확신할 수 있고 또한 실행할 때 마다 다운로드를 받으면 찌꺼기가 남는데 그런게 없이 실행되고 지워지기때문에 아주 깔꼼하다. 단점은 실행할 떄 마다 새로 다운로드를 받아야해서 실행속도가 좀 느리다.

만약 패키지안에 실행파일이 한개가 아니라면

$ npx -p @hoon0123/hi say-hi ko 이렇게 패키지를 다운로드 받아서 뒤에 이름적어준 파일을 실행시키게 할 수 있다.

정말 간단하고 아주 효율적이다. 어디 컴퓨터에 있던지 npm만 깔려있다면 사용할 수 가 있는것이다.

근데 이게 npx 는 내가 설치를 안했으면 설치하고 실행하고 지우지만 글로벌이든 로컬이든 깔려있으면 깔려있는놈 실행한다.

근데 로컬에도 있꼬 글로벌에도 있다면 로컬에있는 애 먼저 실행한다.

즉 실행순서는

  1. 로컬먼저 찾고 없으면
  2. 글로벌에서 찾고 그래도 없으면
  3. 다운로드받아서 실행하고 지운다.

끗.

npm-study's People

Contributors

ihd0628 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.