Last active
November 11, 2019 13:16
-
-
Save samtse/db8b3999b377e4d13b1bd4376c699a74 to your computer and use it in GitHub Desktop.
cannotpost problem in express
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
| "use strict"; | |
| const PORT = process.env.PORT || 5000; | |
| const express = require("express"); | |
| var people; | |
| var mysql = require("mysql") | |
| var connection = mysql.createConnection({ | |
| host: 'localhost', | |
| user: 'root', | |
| password: 'privatePassword', | |
| database: '' | |
| }) | |
| connection.query("SELECT * from sys.test as cnt;", function (err, rows, fields) { | |
| if (err) throw err | |
| console.log('data length = : '+ rows.length); | |
| console.log('The query result is: '+ rows[0].personName); | |
| people = rows; | |
| }); | |
| const app = express(); | |
| app.get('/', function (req, res) { | |
| res.send('GET request to the homepage') | |
| }) | |
| // app.get('/api/peoplelist',(req,res) =>{ | |
| // res.json(people); | |
| // }); | |
| // app.get('/api/peoplelist', function (req, res) { | |
| // res.json(people) | |
| // }) | |
| const bodyParser = require("body-parser"); | |
| app.use(express.static('wwwpub')) | |
| //from docs | |
| app.post('/test', function (req, res) { | |
| res.send('POST request to the test') | |
| }) | |
| app.post('/api/addperson',(req,res) =>{ | |
| var newname = req.body.Name; | |
| console.log("post route hit! with: "); | |
| console.log( req.body); | |
| //const sql ="use sys; insert into test (PersonName) values ('"+ newname+ "');"; | |
| console.log("query: "+ sql); | |
| // connection.query(sql) | |
| }); | |
| app.listen(PORT); | |
| console.log("server started on port: "+PORT); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment