https://beautifier.io/ сделать код красивым
This commit is contained in:
parent
096f60baa0
commit
c1d2600f92
31
index.js
31
index.js
@ -15,14 +15,23 @@
|
|||||||
// })
|
// })
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const http = require('node:http');
|
const http = require('node:http');
|
||||||
const { SerialPort } = require('serialport')
|
const {
|
||||||
const { ReadlineParser } = require('@serialport/parser-readline')
|
SerialPort
|
||||||
|
} = require('serialport')
|
||||||
|
const {
|
||||||
|
ReadlineParser
|
||||||
|
} = require('@serialport/parser-readline')
|
||||||
|
|
||||||
const port = new SerialPort({ path: '/com9', baudRate: 9600 })
|
const port = new SerialPort({
|
||||||
|
path: '/com9',
|
||||||
|
baudRate: 9600
|
||||||
|
})
|
||||||
|
|
||||||
var str = "";
|
var str = "";
|
||||||
|
|
||||||
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
const parser = port.pipe(new ReadlineParser({
|
||||||
|
delimiter: '\r\n'
|
||||||
|
}))
|
||||||
parser.on('data', (data) => {
|
parser.on('data', (data) => {
|
||||||
if (str != data) {
|
if (str != data) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
@ -34,9 +43,9 @@ parser.on('data', (data) => {
|
|||||||
// Create a local server to receive data from
|
// Create a local server to receive data from
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
console.log(req.url);
|
console.log(req.url);
|
||||||
if(req.url=='/'){
|
if (req.url == '/') {
|
||||||
fs.readFile('index.html', (err,data) => {
|
fs.readFile('index.html', (err, data) => {
|
||||||
if(err){
|
if (err) {
|
||||||
res.writeHead(404, "Not Found");
|
res.writeHead(404, "Not Found");
|
||||||
res.write("No file found")
|
res.write("No file found")
|
||||||
res.end();
|
res.end();
|
||||||
@ -48,10 +57,12 @@ if(req.url=='/'){
|
|||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if(req.url=='/pin'){
|
} else if (req.url == '/pin') {
|
||||||
res.writeHead(200, {'Content-Type': 'application/json'});
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
res.end(str);
|
res.end(str);
|
||||||
} else{
|
} else {
|
||||||
res.writeHead(404, "Not Found");
|
res.writeHead(404, "Not Found");
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user