title: <pre>SyntaxError: Unexpected token # in JSON at position 0<br> &nbsp; &nbsp;at JSON.parse
body: <p>I am running this block of NodeJS code and test the login functionality:</p>
  
  <pre><code>const express = require('express');
  const bodyParser = require('body-parser');
  let jwt = require('jsonwebtoken');
  let config = require('./config');
  let middleware = require('./middleware');
  
  class HandlerGenerator {
     login (req, res) {
       let username = req.body.username;
       let password = req.body.password;
       // For the given username fetch user from DB
       let mockedUsername = 'admin';
       let mockedPassword = 'password';
       if (username &amp;&amp; password) {
           if (username === mockedUsername &amp;&amp; password === mockedPassword) {
              let token = jwt.sign({username: username}, 
                          config.secret, 
                          { expiresIn: '24h' // expires in 24 hours });
              // return the JWT token for the future API calls
              res.json({
                 success: true,
                 message: 'Authentication successful!',
                 token: token
             });
           } else {
              res.send(403).json({
                 success: false,
                 message: 'Incorrect username or password'
              });
          }
      } else {
         res.send(400).json({
            success: false,
            message: 'Authentication failed! Please check the request'
         });
      }
   } 
  
   index (req, res) {
     res.json({
       success: true,
       message: 'Index page'
     });
  }
  }
  
  
  // Starting point of the server
  function main () {
  let app = express(); // Export app for other routes to use
  let handlers = new HandlerGenerator();
  const port = process.env.PORT || 8000;
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  // Routes &amp; Handlers
  app.post('/login', handlers.login);
  app.get('/', middleware.checkToken, handlers.index);
  app.listen(port, () =&gt; console.log(`Server is listening on port: ${port}`));
  }
  
  main();
  </code></pre>
  
  <p>The problem is when i run the POST command:</p>
  
  <p>curl --header "Content-Type: application/json"  --request POST --data '{"password":"password", "username":"admin"}' <a href="http://localhost:8000/login" rel="nofollow noreferrer">http://localhost:8000/login</a></p>
  
  <p>I get the error:
  SyntaxError: Unexpected token # in JSON at position 0<br> &nbsp; &nbsp;at JSON.parse</p>
  
  <p>To me thr JSON looks well formatted. Probably something to do with encoding?! Where am i doing mistake?
  thanks.</p>