title: How can I connect to POST method in index.js?
body: <p>Tried to implement a register template with nodejs, console logs the error &quot;POST is not defined&quot;.</p>
  <p>Here index.html</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset=&quot;UTF-8&quot;/&gt;
          &lt;meta name=&quot;viewpost&quot; content=&quot;width=device-width, initial-scale=1.0&quot;/&gt;
          &lt;title&gt;Login &amp; Register with NodeJS&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form id=&quot;reg-form&quot;&gt;
              &lt;input type=&quot;text&quot; autocomplete=&quot;off&quot; placeholder=&quot;Username&quot; id=&quot;username&quot;&gt;
              &lt;input type=&quot;password&quot; placeholder=&quot;Password&quot; id=&quot;password&quot;&gt;
              &lt;input type=&quot;submit&quot; value=&quot;Submit Form&quot;&gt;
          &lt;/form&gt;
          &lt;script&gt;
              const form = document.getElementById('reg-form')
              form.addEventListener('submit', registerUser)
  
  
              async function registerUser(event) {
                  event.preventDefault()
  
                  try {
                      const username = document.getElementById('username').value
                      const password = document.getElementById('password').value
                  } 
                  catch(e) {
                      console.log( &quot;Assignment didn't work &quot; + e.message) 
                  }
                  
                  try {
                      const result = await fetch('./api/register', {
                          method: POST,
                          headers: {
                              'Content-Type': 'application/json'
                          },
                          body: JSON.stringify({
                              username,
                              password
                          }).then((res) =&gt; res.json())
                       })
                       console.log(result)
                  } catch(e) {
                      console.log(e.message)
                  }
              }
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>here the index.js:</p>
  <pre><code>const express = require('express')
  const path = require('path')
  
  const app = express()
  app.use('/', express.static(path.join(__dirname, 'static')))
  app.use(express.json())
  
  app.post('./api/register', async (req, res) =&gt; {
      console.log(req.body)
      res.json({status: 'ok'})
  })
  
  app.listen(9999, () =&gt; {
      console.log('Server up at 9999')
  })
  </code></pre>
  <p>My Server is up on localhost and running, the form is working as well, but it seems as if the POST method can not be called. I didn't connect any database just yet. I'm running on Windows 10. Can somebody tell me why it isn't working?</p>