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

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

View File

@ -8,50 +8,61 @@
// port.on('readable', function () { // port.on('readable', function () {
// console.log('Data:', port.read()) // console.log('Data:', port.read())
// }) // })
// // Switches the port into "flowing mode" // // Switches the port into "flowing mode"
// port.on('data', function (data) { // port.on('data', function (data) {
// console.log('Data:', data.toString('UTF8')) // console.log('Data:', data.toString('UTF8'))
// }) // })
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);
} }
str = data; str = 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();
} else { } else {
res.writeHead(200, { res.writeHead(200, {
'Content-Type': 'text/html' 'Content-Type': 'text/html'
}) })
res.write(data) res.write(data)
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();
} }