Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mysql = require('mysql');
- const express = require('express');
- const parser = require('body-parser');
- var app = express();
- app.use(parser.json);
- var db = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: 'Nandinho12',
- database: 'dbtreino'
- });
- db.connect((err) => {
- if(!err) {
- console.log('DB connection succeded.');
- }
- else {
- console.log('DB connection failed');
- }
- });
- app.listen(3000, () => console.log("Express Server is running"));
- app.get('/', function (req, res) {
- res.send('Hello world');
- });
- app.get('/bino'), (res, req) => {
- console.log("asdaef");
- db.query("SELECT * from users", (err, data, fields) => {
- if(err) throw err;
- console.log(data);
- })
- }
- app.get('/users', (res, req)=> {
- console.log("woow");
- db.query("SELECT * from users", (err,data,fields) => {
- if(!err){
- console.log(data);
- }
- else {
- console.log(err);
- }
- });
- });
Add Comment
Please, Sign In to add comment