Node JS 는 front-end로 많이 설명하는데, 쉽게 생각하면 서버 프로그래밍 언어 + 자바스크립트 입니다.
-> 자바스크립트만 알면, 클라이언트, 서버 개발이 다 가능해 진다.
- 공부 출처 : 유투브 개발자의품격 - 한 시간만에 끝내는 Node.js 입문
- 링크 : https://www.youtube.com/watch?v=toLDNN4FQv
nodemailer
- mailtrap.io -> https://mailtrap.io/
- nodemailer 사용 -> https://nodemailer.com/about/
- npm install nodemailer
mailtrap.io 가입후
이렇게 메일을 보낼수 있는 정보가 나옵니다.
복사하여 코드에 붙여넣기 해주시면 됩니다.
emailSender.js
const nodemailer = require("nodemailer");
const email = {
host: "smtp.mailtrap.io",
port: 개인,
auth: {
user: "개인",
pass: "개인"
}
};
const send = async (option) => {
nodemailer.createTransport(email).sendMail(option, (error, info) => {
if (error) {
console.log(error);
} else {
console.log(info);
return info.response;
}
});
};
let email_data = {
from: 'quf8093@gmail.com',
to: 'quf8093@gmail.com',
subject: '테스트 메일입니다. node js공부중 ',
text: 'node js email test입니다.'
}
send(email_data);
/*
출처 : 유투브 개발자의품격
링크 : https://www.youtube.com/watch?v=toLDNN4FQv
mailtrap.io
nodemailer 사용
*/
실행시키는 방법은 모두 아시겠지만,
터미널 열고
node emailSender.js
입력하면 됩니다. test메일이 잘 온것까지 확인 가능합니다..
Node 로 웹서버 구축 및 DB연동
- npm install express --sava
- 페이지 설정
- npm install mysql --sava
- 구글 -> mysql npm ->https://www.npmjs.com/package/mysql
- MariaDB 연동
const express = require('express');
const app = express();
const server = app.listen(3000, () => {
console.log('Start server : localhost:3000');
});
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
app.get('/', function (req, res) {
res.render('index.html')
})
app.get('/about', function (req, res) {
res.render('about.html')
})
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost', //3306 이 아니였음.. -> maria DB가 존재하는 서버 주소
user: 'root',
password: '내비번',
database: 'b_test'
});
app.get('/db', function (req, res) {
pool.getConnection(function (err, connection) {
if (err) throw err; // not connected!
// Use the connection
connection.query('SELECT * FROM Test', function (error, results, fields) {
res.send(JSON.stringify(results));
console.log('results', results);
// When done with the connection, release it.
connection.release();
// Handle error after the release.
if (error) throw error;
// Don't use the connection here, it has been returned to the pool.
});
});
})
/*
npm install express --sava
페이지설정
npm install mysql --sava
구글 -> mysql npm ->https://www.npmjs.com/package/mysql
마리아디비 연동까지
*/
코드 : https://github.com/ohbyul/nodeJS_restApiServer_frist
위 깃 에서 코드 확인 가능합니다.
veiws폴더 생성후 index.html / about.html
웹 페이지 나눠주고 기존 사용하면 Maria DB로 연동 했습니다.
Node 공부중인데
정말 많은 도움 되었던 유투브 였습니다.
728x90
반응형
'인강\개인공부 > 유튜브 강의' 카테고리의 다른 글
녹화프로그램! HTML, JS로 직접 만들어보기 (3) | 2021.04.16 |
---|
댓글