Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express')
- const app = express()
- const morgan = require('morgan')
- const mysql = require('mysql')
- app.use(morgan('combined'))
- var connection = mysql.createConnection({
- host : 'localhost',
- database : 'dbRestApi',
- user : 'root',
- password : '1234',
- });
- connection.connect(function(err) {
- if (err) {
- console.error('Error connecting: ' + err.stack);
- return;
- }
- console.log('Connected as id ' + connection.threadId);
- });
- connection.query('SELECT * FROM users', function (error, results, fields) {
- if (error)
- throw error;
- results.forEach(result => {
- console.log(result);
- });
- });
- connection.end();
- MacBook-Pro-xxx:nodejs_restapi xxx$ node app.js
- Connected as id 79
- RowDataPacket { id: 1, first_name: 'Tymek', last_name: 'Sala' }
- RowDataPacket { id: 2, first_name: 'Kuba', last_name: 'Cichy' }
- RowDataPacket { id: 3, first_name: 'Huber', last_name: 'Slow' }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement