Tech/NodeJs
-
Object.assign vs spreadTech/NodeJs 2020. 1. 10. 21:22
const obj = { title: 'node.js' } const newObj = { name: '노드제이에스' } //새로운 객체로 통합 Object.assign({}, obj, newObj) //결과 {title:'node.js', name:'노드제이에스'} //다른 방법 ... spread 사용으로 객체를 통합한다. const ret = { ...obj, ...newObj } //spread 사용은 가독성이 좋기 때문에 자주 사용함 const arr = [1,2,3] const newArr = [4,5,6] const out = { ...arr, ...newArr } //output [1,2,3,4,5,6]
-
module.exportTech/NodeJs 2020. 1. 10. 21:18
module.export 로 함수/클래스 등을 export -- sample.js function edit(){} function write(){} module.exports = { edit, //or edit:edit write //or write:write } -------------- -- sampleClass.js class update{} module.exports = update ------- -- sampleDirectExport.js module.exports = { id:'', token:'', fn:() => { console.log('this is a function') } }
-
Nodejs dev env setupTech/NodeJs 2020. 1. 10. 21:11
nodejs install nodejs 공식 사이트의 LTS 버전을 설치 하도록 한다. https://nodejs.org/ko/ 설치후 패키지 관리도구인 npm, npx 을 별도의 설치 없이 사용 가능. NPM 을 사용하여 nodejs 프로젝트 설정 - 작업 디렉터리 생성 mkdir node_project - 작업 디렉터리에서 패키지 초기화 npm init - 패키지 설치 npm install or i - 패키지 설치시 패키지 목록 저장하기 npm install --save-dev - 설치된 패키지 제거 npm uninstall - 전역 으로 설치하기 npm install -g - 전역으로 설치된 패키지 제거 npm uninstall -g NPX 사용 - 설치하지 않고 단순 실행 목적일 경우 사용 한다...