The following url provides a pretty good walkthrough of how to wire up a node/express implementation to read from GCP Cloud SQL:https://medium.com/@austinhale/building-a-node-api-with-express-and-google-cloud-sql-9bda260b040fI implemented the steps in this article and my local implementation is working as expected. However, this url doesn't cover how to wire up inserts/updates. Based on some googling, I came up with the following implementation for a post/insert:// POST method route app.post('/users', function (req, res) { var post = { FirstName: req.FirstName, LastName: req.LastName }; var query = connection.query('INSERT INTO User SET ?', post, function (error, results, fields) { if (error){ console.log(error.message); } }); })I'm POST-ing the following request from Postman as raw JSON:http://localhost:3000/users/ { "FirstName":"John", "LastName":"Smith" }However, the response status is 404 Not Found. The standard GET is working as expected though. Any idea what I might be doing wrong here? Also, I'm new to Node/Express. What's the easiest way to get started debugging? For example, is there a recommended plugin for CDT that I can use for this? The sample code that I used for the GET used console.log("message") but when I tried this approach, nothing appeared to be written out to the node console window or to CDT?
Submitted January 01, 2020 at 04:56PM by random503
No comments:
Post a Comment