I need to write a code for node.js that receives a "post request" (in this case a word String
), and pass this word forward to serial port. Then you receive from this serial port another word and put this word as answer for a "post request".
It should be a simple code, but I do not understand much about node.js and I have read a lot of information and tutorials, but I have not found exactly how to do what I need.
I need this to finalize my little application (I'm far from being a web programmer) and I can not find examples of these in the middle of so much information.
The most I could write was:
var express = require('express')
var app = express()
app.get('/notes', function(req, res) {
res.json({
notes: "World"
})
})
app.listen(3000)
var bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: false
}))
app.post('/notes', function(req, res) {
if (!req.body.notes || typeof req.body.notes != "string") {
res.status(400).send("400 Bad Request")
}
req.user.customData.notes = req.body.notes
req.user.customData.save()
res.status(200).end()
})
And I do not know how to modify this to work with serial port.