https://beautifier.io/ сделать код красивым

This commit is contained in:
Софья Сердитова 2023-05-11 18:58:04 +03:00
parent 096f60baa0
commit c1d2600f92

View File

@ -15,28 +15,37 @@
// })
const fs = require('fs');
const http = require('node:http');
const { SerialPort } = require('serialport')
const { ReadlineParser } = require('@serialport/parser-readline')
const {
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 = "";
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
const parser = port.pipe(new ReadlineParser({
delimiter: '\r\n'
}))
parser.on('data', (data) => {
if (str != data) {
console.log(data);
}
str = data;
if (str != data) {
console.log(data);
}
str = data;
})
// Create a local server to receive data from
const server = http.createServer((req, res) => {
console.log(req.url);
if(req.url=='/'){
fs.readFile('index.html', (err,data) => {
if(err){
if (req.url == '/') {
fs.readFile('index.html', (err, data) => {
if (err) {
res.writeHead(404, "Not Found");
res.write("No file found")
res.end();
@ -48,10 +57,12 @@ if(req.url=='/'){
res.end();
}
})
} else if(req.url=='/pin'){
res.writeHead(200, {'Content-Type': 'application/json'});
} else if (req.url == '/pin') {
res.writeHead(200, {
'Content-Type': 'application/json'
});
res.end(str);
} else{
} else {
res.writeHead(404, "Not Found");
res.end();
}