데이터베이스 연동2 [nodeJS] Node.JS와 mongoDB 연동 방법 MongoDB 서버를 이미 설치하고 실행한 경우를 전제로 작업 진행 1. MongoDB 패키지 설치 npm install mongodb 2. MongoDB 연결 생성 mongodb 패키지를 import하고, 연결 구성 정보 (username, password, hostname, port, database 이름)를 지정 MongoClient 객체를 만든 다음, connect() 함수를 호출하고 연결 URL과 구성 옵션을 전달하여 MongoDB 서버에 연결 const { MongoClient } = require("mongodb"); const uri = "mongodb+srv://username:password@cluster.mongodb.net/database"; const client = new Mon.. 2023. 8. 8. [nodeJS] Node.JS와 mySQL 연동 방법 MySQL 서버를 이미 설치하고 실행한 경우를 전제로 작업 진행 1. MySQL 패키지 설치 npm install mysql 2. MySQL 연결 생성 mysql 패키지를 import 후 연결을 설정할 객체와 연결 정보(호스트, 사용자, 비밀번호, 데이터베이스 이름 등) 입력하고, connect() 메소드를 사용하여 MySQL 서버에 연결 const mysql = require("mysql"); const connection = mysql.createConnection({ host: "localhost", user: "your_username", password: "your_password", database: "your_database", }); connection.connect((error) => {.. 2023. 8. 7. 이전 1 다음