OS모듈
시스템 정보를 가져오는 모듈
(전역X -> require()필수!)
const os = require('os');
주요 메서드
- os.homedir(): 사용자 홈 디렉토리 경로
- os.type(): 운영체제 이름(ex Linux,Darwin...)
- os.arch(): CPU 아키텍처(ex x64)
- os.networkInterfaces(): 네트워크 인터페이스 정보(ex IP,MAX)
- os.hostname(): 호스트 이름
- os.uptime(): 시스템이 켜진 시간
예제
1.app.js만들기
//1.os모듈 가져오기
const os = require('os');
//2.server객체에 os모듈로부터 가져온 값을 value에 넣기
const server = {
type: os.type(),
architecture: os.arch(),
uptime: os.uptime()
};
//3.server객체 출력하기
console.log(server);
2.터미널에서 app.js 실행
$ node app.js
{ type: 'Linux', architecture: 'x64', uptime: 3815.5 }
'개발' 카테고리의 다른 글
| Node.js(with codecademy) - 5 (0) | 2025.06.20 |
|---|---|
| Node.js(with codecademy) - 4 (0) | 2025.06.19 |
| Node.js(with codecademy) - 2 (1) | 2025.06.17 |
| 백준 11650 - 좌표정렬하기 (0) | 2025.06.17 |