I wanted to create a save feature for my flashcard app. The solution I thought of first would be to save details about every card added, so on start the app could retrieve all of that data and format the flashcards the way you left them. I set up a node express js server, but when I post from the form, the page goes blank. However, the data is posted which I just have console logging to the node server. How can I make the page not go blank and just stay on index html and function normally?
NodeJS Server:
const bodyParser = require("body-parser");
const fs = require("fs")
const app = express();
let urlencodedParser = bodyParser.urlencoded({ extended: false });
app.use(express.json());
app.use(express.static("public"));
app.listen(3000, () => {
console.log("Server Started");
})
app.post("/", urlencodedParser, (req, res) => {
//add data to json
console.log(req.body);
res.end();
//then respond by running function AddFlashCard(event)
})
HTML FORM CODE:
<form id="form-container" method="post">
<div class="justify-container">
<div class="formItem" id="box1">
<label for="card-title-input" class="label" id="card-title-label">Card Title:</label>
<input type="text" name="title" id="card-title-input">
</div>
<div class="formItem" id="box2">
<label for="card-front-input" class="label">Card Front:</label>
<textarea name="front" id="card-front-input" cols="30" rows="5" maxlength="160"></textarea>
</div>
<div class="formItem" id="box3">
<label for="card-back-input" class="label">Card Back:</label>
<textarea name="back" id="card-back-input" cols="30" rows="5" maxlength="160"></textarea>
</div>
<div class="formItem" id="box4">
<button type="submit" id="submit">Add Card</button>
</div>
</div>
</form>
After clicking my submit button, page goes blank, and node server outputs as an example,
[Object: null prototype] {
title: 'Title',
front: 'Front',
back: 'Back'
}
This is just the first step of it and not supposed to be fully functional given this code ofcourse, I would just like to start with getting this example data sent with from the form to the server and the page not going blank and functioning otherwise normally.