-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (31 loc) · 820 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const express = require ( 'express' )
const mysql = require("mysql2")
const app = express()
const port = process.env.port || 3000
const fs = require('fs')
app.get('/', (req, res) => {
const connection = mysql.createConnection({
host : "sql.freedb.tech",
port : 3306,
database : "freedb_maie_commerce",
user : "freedb_babs990",
password : "r5ZQ#swQ7Y$RbW4"
})
connection.connect((err)=>{
if(err){
console.log('erreur de connexion : ' +err)
}else{
console.log('connexion reussi')
}
})
connection.query("SELECT * FROM produits" , (err,rows,fieds)=>{
if(err) throw err;
fs.writeFile('produits.json',JSON.stringify(rows),(err)=>{
console.log(err)
})
})
res.send('bonjour')
})
app.listen(port, () => {
console.log('serveur online')
})