Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Setup Express
- const express = require('express');
- const app = express();
- const port = 3000;
- // Setup MySQL
- const mysql = require('mysql');
- // Handle API requests
- app.get('/api/products', (req, res) => {
- const connection = mysql.createConnection({
- host: '192.168.99.100',
- user: 'root',
- password: 'foo123',
- database: 'foo.db'
- });
- connection.connect();
- connection.query('SELECT * FROM products LIMIT 5;', function (err, rows, fields) {
- if (err) {
- throw err;
- }
- res.json(rows);
- });
- connection.end();
- });
- // Start dev server
- app.listen(port, () => console.log(`Server up! Listening ${port}.`));
Add Comment
Please, Sign In to add comment