-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (28 loc) · 873 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const {
exec
} = require('child_process')
const fs = require('fs'),
express = require('express'),
app = express(),
cors = require('cors')
app.options('/print/:printer/:id', cors())
app.post('/print/:printer/:id', cors(), (req, res) => {
const userInfo = req.body.userInfo
const text = `\n------\n> ${userInfo.nome}\n> ${userInfo.stanza} \n> ${userInfo.ristoro}\n-----\n`
const printer = req.params.printer === '1' ? '-P Zebra-TLP2844' : ''
fs.writeFile(`./text/${req.params.id}.txt`, text, function(err) {
if (err) {
return console.log(err)
}
exec(`lpr ${printer} ./text/${req.params.id}.txt`, (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
return
}
})
})
res.send(req.params)
})
app.listen(3000, function() {
console.log('Zebra Print Server running on port 3000!')
})