💻STUDY/BACKEND STUDY

[Node.js] 6주차

coldNoodlePigeon 2022. 5. 15.
  • Node.js and Express.js Full course 강의를 듣고 정리한 내용입니다.

~앞부분은 기본 Node.js에 관한 설명이라 생략합니다.~

 

 

Repl

 

터미널을 통해 node를 실행시키고 어떻게 작동하는지 간단한 작업들을 확인할 수 있다. 이보다 더 복잡해질 경우 cli를 사용한다. 

 

 

Cli

 

vscode를 사용하여 더 복잡한 작업을 눈으로 확인할 수 있다. 실행도 또한 terminal로 확인 가능하다. (주의할 점은 해당 js파일이 있는 경로로 cd하여 이동해야하는 것.) 

 

 

vscode에서 view>terminal로도 바로 실행이 가능하다. 

 

 

global variables in node 

 

__dirname : 현재 디렉토리로의 경로 

__filename : 파일명

require : 모듈을 사용하기 위한 함수 (CommonJS)

module: 현재 모듈에 관한 정보 (file)

process: 프로그램이 어떤 환경에서 실행되는지에 관한 정보 

 

 

 

module

 

노드에 있는 모든 파일들은 모듈이다. 

 

 

alternative syntax 

 

위와 같은 방식으로도 module export를 할 수 있다. 

 

 

Mind Grenade 

 

 

 

Built-in Modules 

 

: OS, Path, Fs, Http 모듈 등 

 

OS module 

const os=require('os') //built-in이므로 ./로 시작안해도 됨. 

//info about current user 
const user=os.userInfo()
console.log(user);

//method returns the system uptime in seconds 
console.log(`The System Uptime is ${os.uptime()} seconds`);

const currentOs={
    name:os.type(),
    release:os.release(),
    totalMem:os.totalmem(),
    freeMem:os.freemem(),
}
console.log(currentOs);

 

Path module

 

'💻STUDY > BACKEND STUDY' 카테고리의 다른 글

[Node.js] MySQL 데이터베이스  (0) 2022.07.26
[Node.js] 7주차  (0) 2022.05.22
[Node.js] 5주차  (0) 2022.05.08
[Node.js] 4주차  (0) 2022.05.01
[Node.js] 3주차  (0) 2022.04.01

댓글