1
I need to write a code for Node.js who receives a "post request" (in this case a word String
), and pass this word forward to serial port. Then get another word from this serial port and put this word in response to a "post request".
It must be a simple code, but I don’t know much about Node.js and I’ve read a lot of information and several tutorials, but I haven’t found how exactly to do what I need.
I need this to finalize my small application (I’m far from being a web programmer) and I can’t find examples in these rooms 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 don’t know how to modify it to work with serial port.
Take a look here: https://github.com/EmergingTechnologyAdvisors/node-serialport
– Sergio