title: Changing command prompt directory from Node.js script
body: <p>I'm trying to change the directory of terminal using with Node.js program but not able to achieve it. Script is run as <code>node app.js dir_name</code> so first I'm creating the directory and then trying to change into that directory using cd command. Directory is created but the directory for terminal is not changed.</p>
  
  <pre><code>#!/usr/bin/env node
  var platform = process.platform; 
  var figlet = require('figlet');
  var chalk = require('chalk');
  
  if(process.argv.length &lt; 3){
      console.log(
         chalk.green(
            figlet.textSync('mdcd', { horizontalLayout: 'full' })
                    )
                 );
      console.log(chalk.red("Please provide a directory name"));
    }else{
  
      if(platform.includes("win")){
        //console.log("Its Windows");
      }else {  
  
              var exec = require('child_process').exec;
              var command_1 = "mkdir "+process.argv[2];
              var command_2 = "cd "+process.cwd()+"/"+process.argv[2];
              exec(command_1, function (error, stdout, stderr) {
                if(error){
                  console.log("Something bad happened"+error);
                }else {               
                   exec(command_2, function (error, stdout, stderr) {
                       if(error){
                          console.log("Something bad happened"+error);
                       }
                   });
                }
              });
      }
  }
  </code></pre>