How to Save Input From HTML form to JSON File Using Body-Parser

PHOTO EMBED

Saved by [deleted user] #html #nodejs

<form action="/new" method="post">

  <input name="title" type="text">
  <input name="description" type="text">
  <input name="steps[0][text]" type="text">
  <input name="steps[0][ingredients]" type="text">
  <input name="steps[1][text]" type="text">
  <input name="steps[1][ingredients]" type="text">
  <button type="submit">Submit Form</button>

</form>
content_copyCOPY

This method assumes you have a Schema Model and are saving the JSON file using the Mongoose package. Also Body-parser package in installed. Example of the JSON Schema we are saving: const recipeSchema = new Schema({ title: { type: String , required: true}, description: { type: String , required: true}, steps:[{ text:{type:String}, ingredients:{type:String} }]});