Node.js 사용법


Category : Node.js

  1. npm init 을 사용하면 여러 개의 질문을 거쳐서 package.json이라는 새로운 파일을 생성해준다.

  2. npm 사이트에서 다양한 모듈을 받아와 자신의 프로젝트에 적용할 수 있다.

    npm install randomcolor
    npm install fs
    ...
    

Node.js의 module


Category : Javascript, Node.js

// calc.js
const add = (a, b) => a + b;
const sub = (a, b) => a - b;

module.exports = {
  moduleName: 'calc module',
  add: add,
  sub: sub,
};

// example.js
const calc = require('./calc');
console.log(calc.add(2, 2)); // 4
console.log(calc.sub(2, 2)); // 0

const { add } = require('./calc');
console.log(add(3, 3)); // 6

🧡 Async & Await


Category : Javascript

async function helloAsync() {
	return 'hello async';
}

console.log(helloAsync()); // Promise { <pending> }

helloAsync().then((res) => {
	console.log(res);
}); // hello async