๊ธ€ ์ž‘์„ฑ์ž: ํƒ์‹œ ์šด์ „์‚ฌ
๋ฐ˜์‘ํ˜•

๐Ÿคทโ€โ™‚๏ธ npm?

npm์€ Node Package Manager์˜ ์•ฝ์–ด๋กœ JavaScript๋ฅผ ์œ„ํ•œ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž์ž…๋‹ˆ๋‹ค. JavaScript Runtime ํ™˜๊ฒฝ์˜ Node.js์˜ ๊ทธ Node์ž…๋‹ˆ๋‹ค.


์„ธ๊ณ„ ์ตœ๋Œ€์˜ ์†Œํ”„ํŠธ์›จ์–ด ์ฐฝ๊ณ 

npm์€ ์„ธ๊ณ„ ์ตœ๋Œ€์˜ ์†Œํ”„ํŠธ์›จ์–ด ์ฐฝ๊ณ ๋กœ 80๋งŒ๊ฐœ๊ฐ€ ๋„˜๋Š” ์ฝ”๋“œ ํŒจํ‚ค์ง€๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์˜คํ”ˆ์†Œ์Šค ๊ฐœ๋ฐœ์ž๋“ค์€ npm์„ ์ด์šฉํ•˜์—ฌ ๊ทธ๋“ค์˜ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค. ๋งŽ์€ ํšŒ์‚ฌ๋“ค๋„ npm์„ ์ด์šฉํ•˜์—ฌ ์‚ฌ์ ์ธ ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•˜๊ณค ํ•ฉ๋‹ˆ๋‹ค.


SO EAAAAAASY

npm์€ ์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํผ๋ธ”๋ฆญํ•œ ์†Œํ”„ํŠธ์›จ์–ด ํŒจํ‚ค์ง€๋“ค์„ ์–ด๋– ํ•œ ๊ฐ€์ž…์ด๋‚˜ ๋กœ๊ทธ์ธ ์—†์ด ๋ชจ๋‘ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค


CLI ์ด์šฉ

npm์€ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ์„ค์น˜ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๊ณคํ•˜๋Š” CLI(Command Line Client)๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.


Windows ์˜ˆ์‹œ

C:\>npm install <package>

Mac OS ์˜ˆ์‹œ

>npm install <package>


npm ์„ค์น˜

npm์€ Node.js์™€ ํ•จ๊ป˜ ์„ค์น˜๋ฉ๋‹ˆ๋‹ค.


์†Œํ”„ํŠธ์›จ์–ด ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €

npm(Node Package Manager)์€ npm์ด ์ฒ˜์Œ์—๋Š” Node.js๋ฅผ ์œ„ํ•œ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๋กœ ๋งŒ๋“ค์–ด์กŒ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋Ÿฐ ์ด๋ฆ„์„ ๊ฐ€์ง€๊ฒŒ ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ชจ๋“  npm ํŒจํ‚ค์ง€๋“ค์€ package.json์ด๋ผ ๋ถˆ๋ฆฌ๋Š” ํŒŒ์ผ์•ˆ์— ์ •์˜๋ฉ๋‹ˆ๋‹ค. package.json์˜ ๋‚ด์šฉ์€ ํ•ญ์ƒ JSON์œผ๋กœ ์“ฐ์—ฌ์ ธ์•ผํ•ฉ๋‹ˆ๋‹ค. ์ ์–ด๋„ ๋‘ ๊ฐœ์˜ ํ•„๋“œ name(ํ”„๋กœ์ ํŠธ์˜ ์ด๋ฆ„)๊ณผ version์€ ํ•ญ์ƒ ์กด์žฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

{  
	"name" : "foo",  
	"version" : "1.2.3",  
	"description" : "A package for fooing things",  
	"main" : "foo.js",  
	"keywords" : ["foo", "fool", "foolish"],  
	"author" : "John Doe",  
	"licence" : "ISC"  
}


Dependencies(์˜์กด์„ฑ) ๊ด€๋ฆฌํ•˜๊ธฐ

npm์€ ์˜์กด์„ฑ์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. npm์—์„œ ์˜์กด์„ฑ์ด๋ž€ ํ•œ ๋งˆ๋””๋กœ ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๊ฐ€ ๋Œ์•„๊ฐ€๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ npm ํŒจํ‚ค์ง€๋“ค์ž…๋‹ˆ๋‹ค. npm์€ ํ•˜๋‚˜์˜ ์ปค๋งจ๋“œ๋กœ ํ”„๋กœ์ ํŠธ์˜ ๋ชจ๋“  ์˜์กด์„ฑ์„ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜์กด์„ฑ์€ ๋˜ํ•œ package.json์— ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.


๋‹น์‹ ์˜ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๊ณต์œ ํ•ด๋ด…์‹œ๋‹ค.

๋งŒ์•ฝ ๋‹น์‹ ์˜ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ npm ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์— ๊ณต์œ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด https://www.npmjs.com/์— ๊ฐ€์ž…ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.


ํŒจํ‚ค์ง€ ํผ๋ธ”๋ฆฌ์‹ฑํ•˜๊ธฐ

package.jsonํŒŒ์ผ๋งŒ ์žˆ๋‹ค๋ฉด ์–ด๋–ค ํด๋”๋ผ๋„ ํผ๋ธ”๋ฆฌ์‹ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

npm์ด ๊น”๋ ค์žˆ๋Š” ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

C:\>npm

npm์— ๋กœ๊ทธ์ธ์ด ๋˜์–ด์žˆ๋Š” ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

C:\>npm whoami

๋งŒ์•ฝ ์•ˆ๋˜์–ด ์žˆ๋‹ค๋ฉด, ๋กœ๊ทธ์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

C:\>npm login  
Username: <your username>  
Password: <your password>

๋‹น์‹ ์˜ ํ”„๋กœ์ ํŠธ๋กœ ์œ„์น˜๋ฅผ ์˜ฎ๊ฒจ์„œ ๋‹น์‹ ์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ํผ๋ธ”๋ฆฌ์‹ฑํ•˜์„ธ์š”

C:\Users\myuser>cd myproject  
C:\Users\myuser\myproject>npm publish

Written with StackEdit.


๋ฐ˜์‘ํ˜•