title: I am trying to create a subscription but an error occurs
body: <pre><code>Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
      at new NodeError (node:internal/errors:387:5)
      at ServerResponse.setHeader (node:_http_outgoing:603:11)
      at ServerResponse.header (C:\github\V2\node_modules\express\lib\response.js:794:10)
      at ServerResponse.send (C:\github\V2\node_modules\express\lib\response.js:174:12)
      at C:\github\V2\app\API\register.js:84:13
      at C:\github\V2\node_modules\mongodb\lib\utils.js:371:9
      at C:\github\V2\node_modules\mongodb\lib\cursor\abstract_cursor.js:260:32
      at C:\github\V2\node_modules\mongodb\lib\cursor\abstract_cursor.js:510:55
      at C:\github\V2\node_modules\mongodb\lib\utils.js:371:9
      at C:\github\V2\node_modules\mongodb\lib\sessions.js:136:24 {
    code: 'ERR_HTTP_HEADERS_SENT'
  </code></pre>
  <p>This is the code in my file that is causing the problem.</p>
  <pre><code>const express = require('express');
  const app = express();
  var MongoClient = require('mongodb').MongoClient;
  var url = &quot;mongodb+srv://web:U*****qe8xe@web-nodejs.b5fppl0.mongodb.net/&quot;;
  const cookisSession = require('cookie-session');
  const bodyParser = require('body-parser');
  const session = require('express-session');
  const mongodbsession = require('connect-mongodb-session')(session);
  const cookieParser = require('cookie-parser');
  const { response } = require('../database');
  app.use(bodyParser.urlencoded({ extended: false })); // เรียกใช้งาน body-parser
  
  app.use(session({
     secret: 'Session-service',
     resave: false, // ต้องการบันทึกค่าหรือไม่
     saveUninitialized: false, // ต้องการบันทึกค่าหรือไม่
     maxAge: 1000 * 60 * 60 * 24 * 7, // กำหนดระยะเวลาการเปิดตัวคุณภาพการเชื่อมต่อกับคอมพิวเตอร์
     store: new mongodbsession({
         uri: 'mongodb+srv://web:U******qe8xe@web-nodejs.b5fppl0.mongodb.net/',
         dbName: 'webjs',
         collection: 'sessions'
     })
  
  }));
  
  
  
  
  
  app.post('/a-login', (req, res) =&gt; {
   const username = req.body.username;
   const password = req.body.password;
  
  
   // เข้ารหัส password
   const hash = require('crypto').createHash('sha256');
   hash.update(password);
   const password_hash = hash.digest('hex');
  
   MongoClient.connect(url, function(err, db) {
     if (err) throw err;
     var dbo = db.db(&quot;webjs&quot;);
     dbo.collection(&quot;users&quot;).find({ name: username, password: password_hash }).toArray(function(err, result) {
       if (err) throw err;
       if (result. Length &gt; 0) {
         res.send(&quot;ยินดีต้อนรับคุณ &quot; + username);
  
         
  
       } else {
         res.send(&quot;ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง&quot;);
       }
       db.close();
     } );
   } );
   if (result.length &gt; 0) {
     // บันทึกค่าลง session
     req.session.username = username;
     req.session.gemd = result[0].gemd;
     req.session.email = result[0].email;
     req.session.id = result[0]._id;
     req.session.save();
  
  
   } else {
     res.send(&quot;ไม่สมารถเข้าสู่ระบบได้&quot;);
   }
  } );
  module. Exports = app;
  </code></pre>
  <p>How should I fix this problem?</p>
  <p>This text was translated by google.</p>