-13 works

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


dashboard+ Project

Posted by @starbucks #html #nodejs

Code snippet:

<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 to Clipboard

More details:

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} }]});


>> Browse more code snippets

more_vert