This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| const pathnode = require('path'); | |
| const { parse: parseqs } = require('querystring'); | |
| const { parse: parsenodeurl } = require('url'); | |
| const METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'ALL']; | |
| const PRE_METHOD = 'GET,POST'; | |
| const PUSH = Array.prototype.push; | |
| const TYPE = 'Content-Type'; | |
| const JSON_TYPE = 'application/json'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var router = express.Router(); | |
| var person = require('./../controller/person'); | |
| router.get('/person', person.all); | |
| router.post('/person', person.create); | |
| router.get('/person/:person_id', person.byId); | |
| router.get('/person/search/:name', person.search); | |
| router.put('/person/:person_id', person.update); | |
| router.delete('/person/:person_id', person.delete); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var db_connect = require('./../common/connection'); | |
| var person = {}; | |
| //get all person | |
| person.all = async function (req, res) { | |
| try { | |
| var query = `select * from person`; | |
| var persons = await db_connect.query(query); | |
| res.send(persons); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mysql = require('mysql'); | |
| var util = require('util'); | |
| var connection = mysql.createConnection({ | |
| host : 'localhost', | |
| user : 'root', | |
| password : '', | |
| database : 'expressmysql', | |
| dateStrings: 'date' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE DATABASE IF NOT EXISTS `expressmysql`; | |
| CREATE TABLE `person` ( | |
| `person_id` INT(11) NOT NULL AUTO_INCREMENT, | |
| `name` VARCHAR(50) NULL DEFAULT NULL, | |
| `address` VARCHAR(50) NULL DEFAULT NULL, | |
| `phone` VARCHAR(15) NULL DEFAULT NULL, | |
| `created_at` TIMESTAMP NULL DEFAULT NULL, | |
| `updated_at` TIMESTAMP NULL DEFAULT NULL, | |
| PRIMARY KEY (`person_id`)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var router = require('./routes/router'); | |
| var app = express(); | |
| app.use(express.json()); | |
| app.use(express.urlencoded({ extended: true })); | |
| app.use('/', router); | |
| app.listen(3000, function(){ | |
| console.log('port 3000') | |
| }); |