I'm using express and I am completely lost how can I get input from switch, I want to create something like real time application when I toggle the switch, something happens on the server side. I use bootstrap so here is piece of html that I`m using
<form action="/apps" method="post">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="Switch">
<label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
</div>
</form>
Here is my code in Node js
app.post('/apps', bodyParser.urlencoded({ extended: true }), (req, res, next) => {
console.log("Shit is working")
});
But nothing seems to happen when I toggle the switch. I appreciate any response or help because I`m new at Node js.
Your
<input>needsvalueandnameattributes:You need to post the form which will send the form data to the server. For that you'll need a
<button>.Your form will look like:
nameattribute you set on the<input>. This will be parsed and added to thereq.bodyobject by Express and thebodyParsermiddleware like so: