title: A twitter api either not connecting on node or some other issue
body: <pre><code>sony@Tesla MINGW64 ~/Downloads/Twitter API JavaScript Node Exercise/1. Introduction to Connecting to Twitter API/tweet
  $ npm start
  
  &gt; tweet@1.0.0 start
  &gt; node index.js
  
  **RESTART**
  node
  node:_http_outgoing:576
      throw new ERR_HTTP_HEADERS_SENT('set');
      ^
  
  Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
      at new NodeError (node:internal/errors:371:5)
      at ServerResponse.setHeader (node:_http_outgoing:576:11)
      at ServerResponse.header (C:\Users\sony\Downloads\Twitter API JavaScript Node Exercise\1. Introduction to Connecting to Twitter API\tweet\node_modules\express\lib\response.js:771:10)
      at ServerResponse.json (C:\Users\sony\Downloads\Twitter API JavaScript Node Exercise\1. Introduction to Connecting to Twitter API\tweet\node_modules\express\lib\response.js:264:10)
      at C:\Users\sony\Downloads\Twitter API JavaScript Node Exercise\1. Introduction to Connecting to Twitter API\tweet\index.js:29:11
      at C:\Users\sony\Downloads\Twitter API JavaScript Node Exercise\1. Introduction to Connecting to Twitter API\tweet\node_modules\twit\lib\twitter.js:127:13
      at onRequestComplete (C:\Users\sony\Downloads\Twitter API JavaScript Node Exercise\1. Introduction to Connecting to Twitter API\tweet\node_modules\twit\lib\twitter.js:347:7)
      at Request.&lt;anonymous&gt; (C:\Users\sony\Downloads\Twitter API JavaScript Node Exercise\1. Introduction to Connecting to Twitter API\tweet\node_modules\twit\lib\twitter.js:364:7)
      at Request.emit (node:events:402:35)
      at Gunzip.&lt;anonymous&gt; (C:\Users\sony\Downloads\Twitter API JavaScript Node Exercise\1. Introduction to Connecting to Twitter API\tweet\node_modules\request\request.js:1076:12)
      at Object.onceWrapper (node:events:509:28)
      at Gunzip.emit (node:events:390:28)
      at endReadableNT (node:internal/streams/readable:1343:12)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    code: 'ERR_HTTP_HEADERS_SENT'
  }
  </code></pre>
  <p>Issue: My localhost also shuts down because of the above-mentioned error. Nodemon is also installed on my node server, and I am on window 10. Is there any credential validation issue in the API?</p>
  <p>Issue: My localhost also shuts down because of the above-mentioned error. Nodemon is also installed on my node server, and I am on window 10. Is there any credential validation issue in the API?</p>
  <p>What steps should I take to troubleshoot?</p>
  <pre><code>const express = require('express');
  const path = require('path');
  const app = express();
  // const bodyParser = require('body-parser');
  const Twit = require('twit')
   
  const T = new Twit({
    consumer_key:         'XXXXXXXXXX',
    consumer_secret:      'XXXXXXXXXX',
    access_token:         'XXXXXXXXXX-fQAQuerobj4eoRRoOx3V49t6uKU8HOn',
    access_token_secret:  'XXXXXXXXXXXXXXXXXXXXX',
    timeout_ms:           60*1000,
    strictSSL:            true,
  })
  
  app.use(express.static(path.join(__dirname, 'public')));
  // app.use(bodyParser.json());
  // app.use(bodyParser.urlencode({extended:false}));
  app.use(express.urlencoded({extended: true})); 
  app.use(express.json());
  
  
  app.get('/tweets/:search', function(req,res) {
    console.log(req.params.search);
    res.json({'status':'Success'})
    T.get('search/tweets', 
      { q: req.params.search, 
        count: 7 }, function(err, data, response) {
        res.json(data)
    })
  })
  
  
  app.listen(3000);
  console.log(&quot;**RESTART**&quot;);
  </code></pre>