250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- items()
- 오버라이딩
- inplace()
- randrange()
- __annotations__
- 파이썬
- node.js
- Database
- fileinput
- discard()
- count()
- fnmatch
- remove()
- __len__
- __sub__
- choice()
- glob
- HTML
- MySqlDB
- JS
- decode()
- shutil
- shuffle()
- View
- zipfile
- locals()
- __getitem__
- MySQL
- CSS
- mro()
Archives
- Today
- Total
흰둥이는 코드를 짤 때 짖어 (왈!왈!왈!왈!왈!왈!왈!왈!왈!왈!왈!)
(Node.js) 1일차 본문
728x90
반응형
1-global.js
console.log(global);
global.hello = () => {
// console.log('hello');
global.console.log('hello');
}
// global.hello();
hello();
2-console.js
console.log('로딩중...');
console.clear();
터미널에 '로딩중...'을 출력하며 clear()는 터미널에사 지금까지 출력된 텍스트들을 지워준다.
개발시 콘솔 사용법
console.log('log'); // 개발
console.info('info'); // 정보
console.warn('warn'); // 개발
console.error('error'); // 에러, 사용자 에러, 시스템 에러
assert(조건문, 출력문)
- 조건문이 true이면 출력문을 출력해준다.
console.assert(2 === 2, '두 값이 같아요!'); // 값이 출력되지 않음
console.assert(2 === 3, '두 값이 달라요!'); // 값이 출력됨
table, dir
const user = {userid:'apple', name:'김사과', age:20, company: {name:'SK', addr: '서울 중구'}};
console.log(user);
console.table(user);
console.dir(user, {showHidden: true, depth: 0, colors: false});
객체를 출력할때 3가지 모습이다.
실행 시간 확인
console.time('for loop');
for(let i=0; i<10; i++){
console.log(i);
}
console.timeEnd('for loop');
time이 시작된 후 timeEnd에 도달할 때 까지 시간을 출력한다.
함수 실행 카운트
function func1(){
console.log('func1() 실행!');
console.count('func1 function');
}
function func2(){
console.log('func2() 실행!');
}
func1();
func2();
func1();
console.countReset('func1 function');
func1();
count는 실행된 순서를 출력하며 countReset을 하면 초기화를 시킨다.
trace 사용법
function func3() {
func4();
}
function func4(){
func5();
}
function func5(){
console.log('func5() 실행!');
console.trace();
}
func3();
trace를 출력하면 함수들이 실행된 순서대로 경로를 출력한다.
3-this.js
class A {
constructor(num){
this.num = num;
}
memberFunction() {
console.log('----- object -----');
console.log(this);
}
}
const a = new A(10);
a.memberFunction();
4-module.js
- 현재 파일에서 외부 파일을 가져와서 사용 할 수 있다.
counter.js
let count = 0;
function increase() {
count++;
}
function getCount() {
return count;
}
module.exports.getCount = getCount;
module.exports.increase = increase;
module.exports를 이용하여 다른 파일에서도 사용할 수 있도록 해준다.
4-module.js
const counter = require('./counter');
counter.increase();
counter.increase();
counter.increase();
console.log(counter.getCount());
counter.js에 존재하는 함수를 가져와 사용할 수 있다.
5-module.js
package.json
먼저 type에 module을 추가하여야 한다.
counter2.js
let count = 0;
export function increase() {
count++;
}
export function getCount() {
return count;
}
export를 이용하면 다른 파일에서 해당 파일을 import 할 때 이용할 수 있다.
5-module.js
import * as counter from './counter2.js';
counter.increase();
counter.increase();
counter.increase();
console.log(counter.getCount());
import 를 이용하여 counter2.js파일에서 export 한 요소들을 사용 할 수 있다.
import { increase, getCount } from "./counter2.js";
increase();
increase();
increase();
console.log(getCount());
중괄호로 특정 함수만 가져와서 사용 할 수 도있다.
728x90
반응형
'Node.js' 카테고리의 다른 글
(Node.js) 기초 지식 (0) | 2023.04.17 |
---|
Comments