title: Express body-parser: Unexpected token # in JSON at position 0
body: <p>I am trying to return user data from a login with Polymer. I have it working with Postman, but am having trouble translating it into Polymer.</p>
  
  <p>In Postman this returns a JSON object, but in Polymer it is returning undefined.</p>
  
  <p>Polymer Client Code [Connecting to node.js server]</p>
  
  <pre><code>&lt;iron-ajax id="ajaxUser"
    url="http://localhost:8080/login"
    method="post"
    handle-as="json"
    content-type="application/json"
    headers='{"Access-Control-Allow-Origin": "*"}'
    params="[[params]]"
    on-response="saveUserCredentials"
    last-response="{{user}}"&gt;&lt;/iron-ajax&gt;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;paper-input id="username"&gt;&lt;/paper-input&gt;
  &lt;paper-input id="password"&gt;&lt;/paper-input&gt;
  &lt;paper-button on-tap="loginUser"&gt;&lt;/paper-button&gt;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>loginUser() {
    this.params = {"username": this.$.username.value, "password": this.$.password.value};
    console.log(this.params); // logs this.params as populated JSON 
    let request = this.$.ajaxUser.generateRequest();
    request.completes.then(req =&gt; {
      console.log(req);       // no log
      console.log(this.user); // no log
    })
  }
  
  saveUserCredentials() {
    console.log(this.user);
  }
  </code></pre>
  
  <p>Server </p>
  
  <pre><code>// Middleware
  app.options('*', cors(corsOptions)) // preflight OPTIONS; put before other routes
  app.use(formData.parse(formBody))   // parse req.body data from `express-form-data` module
  app.use(bodyParser.json())
  app.use(apiLimit)                   // Rate limit applied to all requests, can apply to specific endpoints
  app.use((req, res, next) =&gt; {       // Enable Cross-Origin Resource Sharing (CORS)
    res.header("Access-Control-Allow-Origin", "*")
    res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT")
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, content-type, Accept, Authorization, x-api-key")
    next()
  }) 
  </code></pre>
  
  <p>Error</p>
  
  <blockquote>
    <p>SyntaxError: Unexpected token # in JSON at position 0<br>
    at JSON.parse ()<br>
    at createStrictSyntaxError (C:\node_modules\body-parser\lib\types\json.js:157:10)<br>
    at parse (C:\node_modules\body-parser\lib\types\json.js:83:15)<br>
    at C:\node_modules\body-parser\lib\read.js:121:18<br>
     at invokeCallback (C:\node_modules\raw-body\index.js:224:16)<br>
    at done (C:\node_modules\raw-body\index.js:213:7)<br>
    at IncomingMessage.onEnd (C:\node_modules\raw-body\index.js:273:7)<br>
    at IncomingMessage.emit (events.js:159:13)<br>
    at endReadableNT (_stream_readable.js:1062:12)<br>
    at process._tickCallback (internal/process/next_tick.js:152:19)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/3QDYK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3QDYK.png" alt="Dev Tools"></a></p>