본문 바로가기

nodejs

(11)
nodejs에서 로컬 Date 포맷을 YYMMDDHHmmss로 가져오는 방법 Date() 포맷을 YYMMDDHHmmss로 가져오는 방법입니다. const options = { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, // 24시간 형식으로 표시 timeZone: 'Asia/Seoul', locale: 'ko-KR', // 월,일,연이 아닌 연,월,일 로 표시 }; const dateTimeString = new Date().toLocaleString('ko-KR', options); const numericDateTime = dateTimeString.replace(/[^\d]/g, ''); // 숫자만 추..
nodejs에서 이메일 보내기 Node.js에서 이메일 전송하는 방법입니다. 우선 nodemailer 라이브러리를 설치합니다. npm을 사용하시면 아래를 복붙해주세요 npm install nodemailer 그 후 아래처럼 작성해줍니다. const nodemailer = require('nodemailer'); // SMTP 설정 const transporter = nodemailer.createTransport({ service: 'Gmail', // 이메일 서비스 제공자 (Gmail, Outlook, Yahoo 등) auth: { user: 'your_email@gmail.com', // 보내는 이메일 주소 pass: 'your_password' // 보내는 이메일의 비밀번호 또는 애플리케이션 비밀번호 (안전한 앱 설정 필요) }..
Nodejs에서 암호화 복호화 하기 Node.js 에서 crypto 모듈을 사용해서 암호화 복호화 하기 기본적인 암호화 복호화 방법입니다. const crypto = require('crypto'); // 암호화 함수 function encrypt(text, key) { const iv = crypto.randomBytes(16); const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv); let encrypted = cipher.update(text, 'utf-8', 'hex'); encrypted += cipher.final('hex'); return { iv: iv.toString('hex'), encryptedData: encrypted }; } // 복호화..