Skip to content

Instantly share code, notes, and snippets.

@oxechicao
Last active March 20, 2024 05:23
Show Gist options
  • Save oxechicao/446c215e2b50b80391dd6427a328c25e to your computer and use it in GitHub Desktop.
Save oxechicao/446c215e2b50b80391dd6427a328c25e to your computer and use it in GitHub Desktop.
version: "3"
services:
db:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=rootinha
- MYSQL_DATABASE=dbzin
ports:
- "3306:3306"
app:
build: .
ports:
- "8080:8080"
depends_on:
- db
FROM node:latest
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD node index.js
const mysql = require('mysql2')
const connection = mysql.createConnection({
host : 'db',
port: '3306',
user : 'root',
password : 'rootinha',
database : 'dbzin'
});
connection.connect((error) => {
if (error) {
console.error('Error connecting to MySQL database:', error);
} else {
console.log('Connected to MySQL database!');
}
});
// close the MySQL connection
//
connection.end()
console.log("NICE!")
{
"name": "ntd",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mysql2": "^3.9.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment