title: TypeError: Assignment to constant variable
body: <p>Please help me solve the error. I have attached my index.js code routes.js code and db.js code and the error description.
  I've been trying hard to solve the error.</p>
  <blockquote>
  <p>index.js</p>
  </blockquote>
  <pre><code>const express = require('express');
  const app = express();
  const routes = require('./routes');
  const path = require('path');
  
  const fileUpload = require('express-fileupload');
  const bodyParser = require('body-parser');
  
  const session = require('express-session');
  const auth = require('./routes/auth');
  const {
    con,
    sessionStore
  } = require('./config/db');
  const fs = require('fs');
  
  require('dotenv').config({
    path: path.join(__dirname, '.env')
  });
  const port = process.env.PORT || 3000;
  
  
  // parse application/json
  app.use(bodyParser.json())
  // parse application/x-www-form-urlencoded
  app.use(bodyParser.urlencoded({
    extended: false
  }));
  
  
  //static files 
  app.use(express.static('public'))
  app.use('/css' , express.static(__dirname + 'public/css'))
  app.use('/imgs' , express.static(__dirname + 'public/imgs'))
  
  var sess = {
      secret: 'keyboard cat',
      store: sessionStore,
      cookie: {
        httpOnly: false,
      },
      resave: false,
      saveUninitialized: false
    }
    
    app.use(session(sess));
    app.use(fileUpload());
  //set views
  app.set('view engine' , 'ejs');
  app.set('views', path.join(__dirname, 'views'))
  
  //
  app.use(require('connect-flash')());
  app.use((req, res, next) =&gt; {
    res.locals.messages = require('express-messages')(req, res);
    next();
  });
  app.get('/', (req,res) =&gt;{
      res.render('index22')
  })
  app.get('/login', (req, res) =&gt; {
      res.render('login');
     });
  
     let s;
  
  const loginRequired = (req, res, next) =&gt; {
      if (req.session.username) {
      s = req.session;
      next();
      } else {
      res.redirect('/auth/login');
      }
  }
  // app.get('/new', (req, res) =&gt; {
  //   res.render('new');
  //  });
  
  //  app.get('/show', (req, res) =&gt; {
  //   res.render('show');
  //  });
  
  // app.get('/', loginRequired, (req, res) =&gt; {
  //     res.redirect('/new');
  // });
  // app.get('/', loginRequired, (req, res) =&gt; {
  //   res.redirect('/show');
  // });
  
   
  app.get('/new', loginRequired, routes.new);//call for main index page
  app.post('/new', loginRequired, routes.new);//call for signup post 
  app.get('/show', loginRequired, routes.show);
  
  
  
  
  
  
  
  app.use('/auth', auth);
  
  
  app.listen(port, () =&gt; console.log(`listening on http://${process.env.HOST}:${port}`));
  </code></pre>
  <blockquote>
  <p>routes.js</p>
  </blockquote>
  <pre><code>const {
     con,
     sessionStore
   } = require('./config/db');
  exports.new = function(req, res){
      message = '';
     if(req.method == &quot;POST&quot;){
        const post  = req.body;
        const username= post.username;
        const title= post.title;
        const state= post.state;
        const category= post.category;
        const description= post.description;
   
        if (!req.files)
                  return res.status(400).send('No files were uploaded.');
   
          const file = req.files.uploads;
          const img_name=file.name;
   
           if(file.mimetype == &quot;image/jpeg&quot; ||file.mimetype == &quot;image/png&quot;||file.mimetype == &quot;image/gif&quot; ){
                                   
                file.mv('public/imgs/uploads/'+file.name, function(err) {
                               
                    if (err)
   
                      return res.status(500).send(err);
                          const sql = &quot;INSERT INTO `nt_data`(`username`,`title`,`state`,`category`, `img_name` ,`description`) VALUES ('&quot; + username + &quot;','&quot; + title + &quot;','&quot; + state + &quot;','&quot; + category + &quot;','&quot; + image + &quot;','&quot; + description + &quot;')&quot;;
   
                              const query = con.query(sql, function(err, result) {
                                   res.redirect('show/'+result.insertUsername);
                              });
                         });
            } else {
              message = &quot;This format is not allowed , please upload file with '.png','.gif','.jpg'&quot;;
              res.render('new.ejs',{message: message});
            }
     } else {
        res.render('new');
     }
   
  };
  
  exports.show = function(req, res){
      const message = '';
      const username = req.params.username;
      const sql=&quot;SELECT * FROM `nt_data` WHERE `username`='&quot;+username+&quot;'&quot;; 
      con.query(sql, function(err, result){
        if(result.length &lt;= 0)
        message = &quot;show not found!&quot;;
        
        res.render('show.ejs',{data:result, message: message});
     });
  };
  </code></pre>
  <blockquote>
  <p>db.js</p>
  </blockquote>
  <pre><code>const mysql = require('mysql');
  const path = require('path');
  const session = require('express-session');
  const MySQLStore = require('express-mysql-session')(session);
  require('dotenv').config({ path: path.join(__dirname, '../.env') });
  
  // config for your database
  const con = mysql.createConnection({
      user: process.env.DB_USER,
      password: process.env.DB_PASSWORD,
      server: process.env.DB_HOST,
      database: process.env.DB_NAME,
      port: parseInt(process.env.DB_PORT)
  });
  
  var sessionStore = new MySQLStore({}/* session store options */, con);
  
  // connect to your database
  con.connect((err) =&gt; {
      if (err) throw err;
      console.log(&quot;Connected to database&quot;);
  });
  
  module.exports = { con, sessionStore };
  </code></pre>
  <blockquote>
  <p>Description of the error:</p>
  </blockquote>
  <pre><code>C:\Users\hp\Desktop\Internship\Nt\node_modules\mysql\lib\protocol\Parser.js:437
        throw err; // Rethrow non-MySQL errors
        ^
  
  TypeError: Assignment to constant variable.
      at Query.&lt;anonymous&gt; (C:\Users\hp\Desktop\Nt\routes.js:50:12)
      at Query.&lt;anonymous&gt; (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\Connection.js:526:10)
      at Query._callback (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\Connection.js:488:16)
      at Query.Sequence.end (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
      at Query._handleFinalResultPacket (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\protocol\sequences\Query.js:149:8)
      at Query.EofPacket (C:\Users\hp\Desktop\\Nt\node_modules\mysql\lib\protocol\sequences\Query.js:133:8)
      at Protocol._parsePacket (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\protocol\Protocol.js:291:23)
      at Parser._parsePacket (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\protocol\Parser.js:433:10)
      at Parser.write (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\protocol\Parser.js:43:10)
      at Protocol.write (C:\Users\hp\Desktop\Nt\node_modules\mysql\lib\protocol\Protocol.js:38:16)
  </code></pre>
  <p>I guess mainly the error is in the routes.js file
  Any help will be highly appreciated.
  Thank you</p>