Node js html form Написать функцию Delete. и тест jest node js
Написать функцию Delete. Не могу не решить не найти, как подружить форму html и app. Delete
My quest
Pogoda w Kraju
Aktualizacja dannych
Location:
temperature: temperaturę w st. C
C
humidity: wilgotność powietrza w %
%
pressure: ciśnienie w hPa
hPa
Location:
temperature: temperaturę w st. C
C
humidity: wilgotność powietrza w %
%
pressure: ciśnienie w hPa
hPa
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var fs = require('fs');
const path = require('path');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static(__dirname + '/public'));
app.post('/process_post', (req, res) => {
// należy utworzyć nowy obiek
const newWeather = [{
"id": 1,
location: req.body.location},
{"id": 2,
temperature: req.body.temperature},
{"id": 3,
humidity: req.body.humidity},
{"id": 4,
pressure: req.body.pressure
}];
console.log(req.body)
// читаем актуальные данные
const weather = JSON.parse(fs.readFileSync("weather.json"));
// dodać do nich nową pogodę
weather.push(newWeather);
// записать изменения
fs.writeFileSync("weather.json", JSON.stringify(weather));
res.json(newWeather);
});
app.use(express.static('public'));
app.get('/process_get', function(req, res) {
const records = JSON.parse(fs.readFileSync("weather.json"));
const weather = JSON.parse(fs.readFileSync("weather.json"));
res.json(weather);
});
app.get('/process_delete', function (req, res) {
// First read existing users.
const weather = JSON.parse(fs.readFileSync("weather.json"));
let removed = weather.splice(0, 2);
alert( removed );
fs.writeFileSync("weather.json", JSON.stringify(weather));
});
var server = app.listen(8081, function() {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at //%s:%s", host, port)
})
Заявки фрилансеров

