Node Modules

vancouver·2023년 5월 4일
0

const

var은 재정의가 가능 하지만 const는 재정의 불가
ex.

var a = 2		const a = 2
	a = 5 (o)	 a = 5 (x)

Node Package Moudles (NPM)

NPM이란

개발자가 누구나 사용하기 쉽게 만들어놓은 코드
https://www.npmjs.com/

npm init

package를 만드는 명령어

This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (intro-to-node)
version: (1.0.0)
description: This is a intro to node project
entry point: (index.js)
test command:
git repository:
keywords:
author: Jang hoon
license: (ISC)
About to write to C:\Users\82102\Desktop\intro-to-node\package.json:

{
  "name": "intro-to-node",
  "version": "1.0.0",
  "description": "This is a intro to node project",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Jang hoon",
  "license": "ISC"
}


Is this OK? (yes)

마지막으로 엔터를 누르면 package파일이 생성

ex. superheroes Name

https://www.npmjs.com/package/superheroes

javascript

//jshint esversion:6
const superheroes = require('superheroes');

var mySuperHeroName = superheroes.random()

console.log(mySuperHeroName);

Terminal

node index.js

0개의 댓글