모듈이란?
- 기능을 떼서 조립할 수 있는 형태로 만든 부분
<script>
태그를 이용한다.require
를 이용한다.const fs = require('fs') // 파일 시스템 모듈 불러오기
const dns = require('dns') // DNS 모듈 불러오기
$ npm install underscore
// node_modules에 underscore가 설치된 것.
// 이제 node.js 내장 모듈을 사용하듯 사용할 수 있다.
const _ = require('underscore');
console.log(__dirname)
을 찍어보면/Users/hyunsoo/Desktop/note
와 같이 나온다.File System(fs)와 path 모듈, __dirname을 이용해 디렉토리 작업을 할 수 있다.
const fs = require('fs');
const path = require('path');
const dirPath = path.join(__dirname, '/pictures');
fs.mkdirSync(dirPath);
pictures
폴더를 하나 만든다.