본문 바로가기
개발정리 (nodeJS)

[nodeJS] Node.js 개발에 흔히 사용되는 라이브러리 5개

by 할리갈리0 2023. 6. 13.

1. Express

Node.js를 위한 가벼운 웹 애플리케이션 프레임워크, 빠르게 API 개발이 가능

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => res.send('Hello World!'));

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));

 

2. Axios 

Promise 기반의 HTTP 요청 라이브러리

const axios = require('axios');

axios.get('https://api.example.com/data')
  .then(response => console.log(response.data))
  .catch(error => console.log(error));

 

3. Socket.io

웹 소켓을 위한 라이브러리, 실시간 애플리케이션 개발 및 채팅 기능 구현에 사용

const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);

app.get('/', (req, res) => res.sendFile(__dirname + '/index.html'));

io.on('connection', socket => {
  socket.on('chat message', msg => io.emit('chat message', msg));
});

http.listen(3000, () => console.log('listening on *:3000'));
<script src="/socket.io/socket.io.js"></script>
<script>
  const socket = io();
  // ...
</script>

 

4. Moment

Node.js에서 다양한 날짜 및 시간 형식을 처리하기 위한 라이브러리

const moment = require('moment')

// 날짜 및 시간 format 변경
const now = moment()
console.log(now.format('MMMM Do YYYY, h:mm:ss a')) // june 13th 2023, 11:46:05 am

 

5. Nodemon 

개발 환경에서 Node.js 애플리케이션을 자동으로 재시작해 주는 도구

// package.json

"scripts": {
  "dev": "nodemon app.js"
}
npm run dev

 

반응형