public:computer:node.js

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
public:computer:node.js [2021/10/01 21:35] alexpublic:computer:node.js [2023/01/03 09:54] (current) alex
Line 4: Line 4:
  
 ==== 특징 ==== ==== 특징 ====
-  * 비동기 입출력 방식 +  * 비동기 입출력 방식 (Non-blocking) I/O 
-  * 이벤트 기반 입출력 방식+  * 이벤트 기반 입출력 방식 (Event Loop) 
 +  * Single Thread
   * 모듈   * 모듈
  
 ==== 개발도구 ==== ==== 개발도구 ====
   * 편집기 VSCode   * 편집기 VSCode
 +    * Extentions
 +      * ES6 Code Snippets
 +      * ESLint
 +      * Prettier - Code formatter
 +      * Live Server
   * 크롬 브라우저   * 크롬 브라우저
   * 노드   * 노드
  
 +==== Install ====
 +
 +=== Install Node.js on MacOS ===
 +brew 설치 <cli>
 +$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
 +</cli>
 +
 +node 설치 <cli>
 +$ brew install node
 +</cli>
 +
 +
 +=== Install Node.js on Ubuntu ===
 +  * Install Node.js on Ubuntu <sxh bash>
 +# 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
 +</sxh>
 +
 +  * nvm <sxh bash>
 +$ 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>
 +</sxh>
 +  * npm update <sxh bash>
 +$ npm install -g npm@latest
 +$ npm -v
 +</sxh>
 +
 +=== Install Vue.js ===
 +{{page>public:computer:vuejs#install_vuejs&noheader}}
 +
 +
 +
 +==== Modules ====
  
   * https/http2 모듈   * https/http2 모듈
Line 37: Line 93:
  
  
 +==== typescript ====
 +  - 디렉토리 생성 (mkdir)
 +  - 프로젝트 생성 (npm init)
 +  - 타입스크립트 모듈 설치
 +  - tsconfig.json 생성
 +  - 타입 추가 (npm i @types/node)
 +  - ts-node 설치 (npm i -g ts-node)
  
  
 +  * [[https://defineall.tistory.com/704|[Node.js] Node.js에서 Typescript 사용하기 / ts-node, @types/node]]
 +
 +
 +
 +
 +
 +
 +==== 가상환경 ====
 +  * nodeenv
 +  * nvm-windows [[https://github.com/coreybutler/nvm-windows|NVM for Windows @github.com]]
 +    * C:\Users\%username%\AppData\Roaming\nvm\setting.txt; make sure ANSI to UTF-8
 +  * <cli prompt="> " comment="  # ">
 +> nvm ls   # 설치된 Node.js 확인
 +> nvm install <version> [arch]  # Node.js 설치
 +> nvm use <version>  # Node.js 버전 변경
 +</cli>
 +
 +
 +  * [[https://dreamholic.tistory.com/101|node 버전 관리기 nodenv 를 설치해 봅시다.]]
 +  * [[https://jojoldu.tistory.com/569|nodeenv를 활용한 프로젝트별 node 가상 환경 관리]]
 +  * [[https://kdydesign.github.io/2020/09/16/nvm-for-windows/|NVM으로 Windows 환경에서 Node 버전 관리하기]]
 +
 +
 +==== 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 ====
 +<cli>
 +$ node <file>
 +</cli>
 +
 +
 +==== 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 ====
 +<cli>
 +$ npm install -g json-server
 +</cli>
 +
 +<cli>
 +$ json-server --watch <file>
 +</cli>
 +
 +==== express ====
 +<cli>
 +$ npm install express
 +</cli>
 +
 +  * 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 =====
 +  * [[https://github.com/nvm-sh/nvm|Node Version Manager]]
  
  
 +<button type="default" size="xs" collapse="toc">book toc</button>
 +<collapse id="toc" collapsed="true">
 ==== 01 | 노드에 대해 알아보고 개발 도구 설치하기 ==== ==== 01 | 노드에 대해 알아보고 개발 도구 설치하기 ====
 노드란 무엇일까? 노드란 무엇일까?
Line 347: Line 561:
 레디스로 subscribe, publish 하기 레디스로 subscribe, publish 하기
 채팅 서버에서 레디스를 사용하는 샘플 채팅 서버에서 레디스를 사용하는 샘플
 +</collapse>
  • public/computer/node.js.1633091744.txt.gz
  • Last modified: 2021/10/01 21:35
  • by alex