Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // load our app server using express somehow....
- const express = require('express')
- const app = express()
- const morgan = require('morgan')
- const mysql = require('mysql')
- app.use(morgan('combined'))
- const connection = mysql.createConnection({
- host: 'localhost',
- database: 'dbRestApi',
- user: 'root',
- password: '973f192g846',
- });
- connection.connect(function (err) {
- if (err) {
- console.error('Error connecting: ' + err.stack);
- return;
- }
- console.log('Connected as id ' + connection.threadId);
- });
- app.get("/users", (req, res) => {
- connection.query('SELECT * FROM users', function (error, results, fields) {
- if (error)
- throw error;
- console.log(results);
- res.json(result);
- });
- });
- connection.end();
- app.get("/", (req, res) => {
- console.log("Responding to root route")
- res.send("Hello from ROOOOOT")
- })
- // localhost:3003
- app.listen(3006, () => {
- console.log("Server is up and listening on 3003...")
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement