Book Image

Node.js By Example

Book Image

Node.js By Example

Overview of this book

Table of Contents (18 chapters)
Node.js By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Posting and storing text


As in the previous chapters, we have a feature that requires changes in both the frontend and backend parts of our application. We will need an HTML form that accepts the user's text, a new model that handles the communication with the backend, and of course, changes in the API. Let's start by updating our home page.

Adding a form to post text messages

We have a home page that displays a simple title. Let's use it and add a <textarea> tag to send content to the API. Later in this chapter, we will use the same page to display the user's feed. Let's replace the lonely <h1> tag with the following markup:

{{#if posting === true}}
  <form enctype="multipart/form-data" method="post">
    <h3>What is on your mind?</h3>
    {{#if error && error != ''}}
      <div class="error">{{{error}}}</div>
    {{/if}}
    {{#if success && success != ''}}
      <div class="success">{{{success}}}</div>
    {{/if}}
   ...