title: How to change values dynamically in Node.js?
body: <p>I am developing a basic chat functionality in Node.js. So , i have list of users list , by clicking on each index i can get the unique values , which will help me to do private Client-Server chatting. But i am not able to figure out how can i change the value in <strong>app.js</strong> file.</p>
  
  <p><strong>Node.js code</strong></p>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var express = require('express'),
  app = express(),
  server = require('http').createServer(app),
  io = require('socket.io').listen(server);
  num = "1";
  
    app.set('view engine', 'ejs');    
    server.listen(4000);
  
          app.get('/', function(req, res){
               //res.sendfile(__dirname + '/index.html');
               res.render(__dirname + '/index.html', { num: num });
         });
  
          io.sockets.on('connection', function(socket){
  
             socket.on('send message'+num, function(data){
                 io.sockets.emit('new message'+num, data);
          }); 
  
   });
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;body&gt;
  &lt;div id="chat"&gt;&lt;/div&gt;
  &lt;form id="send-message"&gt;
      &lt;input size="35" id="message"&gt;&lt;/input&gt;
      &lt;input type="submit"&gt;&lt;/input&gt;
  &lt;/form&gt;
  
  &lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
  &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      jQuery(function($){
          var socket = io.connect();
  
          var $messageForm = $('#send-message');
          var $messageBox = $('#message');
          var $chat = $('#chat');
          var msg = $('#message').val();
          var num = "1";
  
          $messageForm.submit(function(e){
              e.preventDefault();
  
              socket.emit('send message'+num, $messageBox.val());
              $messageBox.val('');
          });
  
          socket.on('new message'+num, function(data){
              $chat.append(data + "&lt;br/&gt;");
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>TypeError: Property 'engine' of object #&lt;View&gt; is not a function
  at View.render (C:\node_demo\chat\node_modules\express\lib\view.js:76:8)
  at Function.app.render (C:\node_demo\chat\node_modules\express\lib\application.js:506:10)
  at ServerResponse.res.render (C:\node_demo\chat\node_modules\express\lib\response.js:756:7)
  at C:\node_demo\chat\app.js:16:6
  at callbacks (C:\node_demo\chat\node_modules\express\lib\router\index.js:161:37)
  at param (C:\node_demo\chat\node_modules\express\lib\router\index.js:135:11)
  at pass (C:\node_demo\chat\node_modules\express\lib\router\index.js:142:5)
  at Router._dispatch (C:\node_demo\chat\node_modules\express\lib\router\index.js:170:5)
  at Object.router (C:\node_demo\chat\node_modules\express\lib\router\index.js:33:10)
  at next (C:\node_demo\chat\node_modules\express\node_modules\connect\lib\proto.js:190:15)
  </code></pre>
  
  <p>I can able to change the <strong>"num"</strong> variable dynamically in index.html but i cannot find out how can i do the same in <strong>app.js</strong> file. How can i pass the value to app.js file.</p>
  
  <p>Please let me know , suggest me some good solution.</p>