public:computer:node.js
This is an old revision of the document!
Table of Contents
Node.js
What is node.js
특징
- 비동기 입출력 방식 (Non-blocking) I/O
- 이벤트 기반 입출력 방식 (Event Loop)
- Single Thread
- 모듈
개발도구
- 편집기 VSCode
- Extentions
- ES6 Code Snippets
- ESLint
- Prettier - Code formatter
- Live Server
- 크롬 브라우저
- 노드
Install
brew 설치
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
node 설치
$ brew install node
Vue CLI 설치
$ npm install -g @vue/cli or $ yarn global add @vue/cli or $ yarn dlx @vue/clie $ vue --version # 확인 $ npm list -g --depth=0 # npm 설치 리스트 확인
Vue CLI 삭제
$ npm uninstall -g vue-cli
vue 프로젝트 생성
$ vue create <프로젝트 이름> $ cd <프로젝트 이름> $ npm run serve
vuetify 패키지 추가
$ vue add vuetify
vue-router 설치
$ vue add router
vuex 설치
$ vue add vuex
axios 설치
$ vue add axios
Install Node.js on Ubuntu
- Install Node.js on Ubuntu
# to install node.js we need CURL $ sudo apt install -y curl # install node.js using apt package manager $ sudo apt update & sudo apt upgrade -y $ sudo apt install nodejs $ nodejs -v $ sudo apt install npm $ npm -v # using PPA $ curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh # version 18.x $ sudo bash nodesource_setup.sh $ sudo apt-get install nodejs $ sudo apt-get install build-essential
- nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash $ source ~/.bashrc $ nvm list-remote $ nvm install <version> $ nvm list $ nvm use <version>
- npm update
$ npm install -g npm@lsatest $ npm -v
Modules
- https/http2 모듈
- express, express-session
- multer
- morgan
- static
- cookie/session
- sequlize
- mongoose
- passport
- jwt token
- test; unit → test coverage → integration test → load test →
- web socket; ws, socket.io,
- commander, inquirer
- redis, memcache
- cross-env
- pm2
- sanitize-html, csurf
- winston
- helmet, hpp
- connect-redis
- template engines; pug, nunjucks
typescript
- 디렉토리 생성 (mkdir)
- 프로젝트 생성 (npm init)
- 타입스크립트 모듈 설치
- tsconfig.json 생성
- 타입 추가 (npm i @types/node)
- ts-node 설치 (npm i -g ts-node)
가상환경
- nodeenv
- nvm-windows NVM for Windows @github.com
- C:\Users\%username%\AppData\Roaming\nvm\setting.txt; make sure ANSI to UTF-8
> nvm ls # 설치된 Node.js 확인 > nvm install <version> [arch] # Node.js 설치 > nvm use <version> # Node.js 버전 변경
JavaScript Basics
- 변수 선언
- var
- let
- const
- Arrow Function
- Array
- sort()
- filter()
- map()
- reduce()
- Template Literals; back tick
` - Spread Operator; 배열에서 iteration 형태의 데이터 요소를 하나하나로 모두 분해해서 사용
- Object Destructuring; { , } = object
- Array Destructuring; [ , ] = array
- Default Function Parameter; same as c++, define default value in argument
- Rest Parameter; …args
- Promise; 비동기 처리에 사용 new Promise((resolve, reject) ⇒ {}});
- Async/Await; 비동기
- Regular Expression
- exec()
- test()
- match()
- search()
- replace()
- split()
Start
$ node <file>
Node.js 내장 모듈과 객체
- Console
- console.log(내용, …args)
- console.error(…)
- console.table(테이블형 데이터)
- console.time(레이블) / console.timeEnd(레이블)
- console.dir(오브젝트, 옵션)
- Timers
- setTimeout(콜백함수, 밀리초)
- setInterval(콜백함수, 밀리초)
- setImmediate(콜백함수)
- Process
- listeners
- beforeExit
- exit
- disconnect
- message
- process.env
- process.nextTick
- process.exit()
- OS
- Path
- path.basename(path[,ext])
- path.delimiter
- path.dirname(path)
- path.extname(path)
- path.format(pathOjbject)
- path.isAbsolute(path)
- path.join([…paths])
- path.parse(path)
- path.sep
- URL;
- WHATWG API
- url.parse()
- Crypto
- File system
- fs.readFile(path, [options], callback)
- fs.readFileSync(path, [options])
- fs.writeFile(path, data, [options], callback)
- writeFileSync(path, data [options])
- fs.watchFile(filename[, options], listener)
json-server
$ npm install -g json-server
$ json-server --watch <file>
express
$ npm install express
- middlewares
- body-parser
- compression
- connect-rid
- cookie-parser
- cors
- csurf
- errorhandler
- method-override
- morgan
- multer
- response-time
- serve-favicon
- serve-index
- serve-static
- express-session
- connect-timeout
- vhost
Useful
- winston
- nodemailer
- node-cron
- xlsx
- xlsx-js-style
- ics
- socket.io
- axios
- cheerio
- forever
- pm2
References
public/computer/node.js.1672645602.txt.gz · Last modified: by alex