index.js 983 Bytes
var express = require('express')

var app = express()

var mysql = require('mysql')

var router = express.Router();

var path = require('path')


var connection = mysql.createConnection({
    host : 'localhost',
    port : 3306,
    user:'root',
    password : 'ksmhjh88',
    database : 'nodetest'
})

connection.connect()

router.post('/ajax',function(req,res) {

    console.log("latitude :",req.body.latitude)
    console.log("longitude :",req.body.longitude)

    var latitude = req.body.latitude;
    var longitude = req.body.longitude;
    var title = req.body.title;

    //var responseData = {'result' : 'ok' , 'email' : req.body.email};
    //res.json(responseData)

    //DB 처리
    var responseData = {};
    var sql = {title: title,latitude: latitude, longitude: longitude};
    var query = connection.query('insert into market set ?' ,sql, function(err,rows) {

        if(err) throw err
        return res.json({'result' : 1});
    })

})

module.exports = router;