title: Nodemon crashes in the middle of the process without showing any error message, how do i resolve it?
body: <p>I am running a script that is getting the files from Google drive and putting it in the s3.
  Now when i run the script, the process goes smoothly for sometime then app suddenly  crashes without any error message, the script takes input also so couldn't find a way to use <code>nohup</code></p>
  <p>The code is like this</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"use strict";
  const fs = require("fs");
  const readline = require("readline");
  const { google } = require("googleapis");
  const { upload_to_s3, emptyFolder, s3_exist } = require("./helper");
  const prompt = require("prompt");
  
  const SCOPES = ["https://www.googleapis.com/auth/drive"];
  // The file token.json stores the user's access and refresh tokens, and is
  // created automatically when the authorization flow completes for the first
  // time.
  const TOKEN_PATH = "token.json";
  
  // Load client secrets from a local file.
  fs.readFile("credentials.json", (err, content) =&gt; {
    if (err) return console.log("Error loading client secret file:", err);
    // Authorize a client with credentials, then call the Google Drive API.
    authorize(JSON.parse(content), listFiles);
  });
  
  /**
   * Create an OAuth2 client with the given credentials, and then execute the
   * given callback function.
   * @param {Object} credentials The authorization client credentials.
   * @param {function} callback The callback to call with the authorized client.
   */
  function authorize(credentials, callback) {
    const { client_secret, client_id, redirect_uris } = credentials.installed;
    const oAuth2Client = new google.auth.OAuth2(
      client_id,
      client_secret,
      redirect_uris[0]
    );
  
    // Check if we have previously stored a token.
    fs.readFile(TOKEN_PATH, (err, token) =&gt; {
      if (err) return getAccessToken(oAuth2Client, callback);
      oAuth2Client.setCredentials(JSON.parse(token));
      callback(oAuth2Client);
    });
  }
  
  /**
   * Get and store new token after prompting for user authorization, and then
   * execute the given callback with the authorized OAuth2 client.
   * @param {google.auth.OAuth2} oAuth2Client The OAuth2 client to get token for.
   * @param {getEventsCallback} callback The callback for the authorized client.
   */
  function getAccessToken(oAuth2Client, callback) {
    const authUrl = oAuth2Client.generateAuthUrl({
      access_type: "offline",
      scope: SCOPES,
    });
    console.log("Authorize this app by visiting this url:", authUrl);
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
    });
    rl.question("Enter the code from that page here: ", (code) =&gt; {
      rl.close();
      oAuth2Client.getToken(code, (err, token) =&gt; {
        if (err) return console.error("Error retrieving access token", err);
        oAuth2Client.setCredentials(token);
        // Store the token to disk for later program executions
        fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) =&gt; {
          if (err) return console.error(err);
          console.log("Token stored to", TOKEN_PATH);
        });
        callback(oAuth2Client);
      });
    });
  }
  
  /**
   * Lists the names and IDs of up to 10 files.
   * @param {google.auth.OAuth2} auth An authorized OAuth2 client.
   */
  async function listFiles(auth) {
    let page_size;
    let page_token;
    prompt.start();
  
    try {
      prompt.get(
        ["stage [d (dev),s (staging),p (prod)]", "pageSize", "pageToken"],
        function (err, result) {
          if (err) {
            return onErr(err);
          }
          let stage;
          let count = 0;
          let total;
          if (
            result["stage [d (dev),s (staging),p (prod)]"] === "d" ||
            result["stage [d (dev),s (staging),p (prod)]"] === "dev"
          ) {
            stage = "dev";
          } else if (
            result["stage [d (dev),s (staging),p (prod)]"] === "s" ||
            result["stage [d (dev),s (staging),p (prod)]"] === "staging"
          ) {
            stage = "staging";
          } else if (
            result["stage [d (dev),s (staging),p (prod)]"] === "p" ||
            result["stage [d (dev),s (staging),p (prod)]"] === "prod"
          ) {
            stage = "prod";
          } else {
            console.log(
              "invalid input, default is chosen",
              result["stage [d (dev),s (staging),p (prod)]"]
            );
            stage = "dev";
          }
          // await emptyFolder("/tmp");
          console.log("Getting the files");
          console.log("  stage: " + stage);
          page_size = result.pageSize || 1000;
          console.log("  pageSize: " + page_size);
          page_token = String(result.pageToken) || null;
          console.log("  pageToken: " + page_token);
          const drive = google.drive({ version: "v3", auth });
          drive.files.list(
            {
              includeItemsFromAllDrives: true,
              supportsAllDrives: true,
              pageSize: page_size,
              pageToken: page_token,
              fields: "nextPageToken,files(id,mimeType, name,fileExtension)",
              includeRemoved: false,
            },
            async (err, res) =&gt; {
              if (err) return console.log("The API returned an error: " + err);
              const files = res.data.files;
              // console.log(res.data);
              // console.log(files);
              if (res.data.nextPageToken) {
                console.log("nextPageToken :", res.data.nextPageToken, "\n");
              }
              let promises = [];
              if (files.length) {
                const filesWithExt = files.filter((file) =&gt; {
                  if (file.fileExtension) {
                    return file;
                  }
                });
                total = filesWithExt.length;
                console.log("Total files", files.length);
                console.log("Total files to be moved", filesWithExt.length);
                console.log("Files:");
                // let t = 1;
                // files.map((file) =&gt; {
                //   console.log(`${file.name} - (${file.id}) [${file.mimeType}]`);
                //   // console.log(t);
                //   // t = t + 1;
                // });
                for (let i = 0; i &lt; files.length; i++) {
                  const file = files[i];
  
                  const tmpName = file.name;
                  const filePath = `/tmp/${tmpName}`;
                  let path = tmpName;
                  if (file.fileExtension) {
                    const exist = await s3_exist(`migration-temp-${stage}`, path);
                    if (exist) {
                      console.log(path, " already exists in s3, skipped", exist);
                    } else {
                      promises.push(
                        await downloadFile(stage, file.id, path, auth)
                      );
                    }
  
                    count = count + 1;
                    console.log("..... ", total - count, " remaining");
                  }
                }
                await Promise.all(promises).then(async (result) =&gt; {
                  console.log(result);
                  if (res.data.nextPageToken) {
                    console.log("nextPageToken :", res.data.nextPageToken, "\n");
                  }
  
                  // await emptyFolder("/tmp");
                  process.exit(0);
                });
              } else {
                console.log("No files found.");
              }
            }
          );
        }
      );
    } catch (err) {
      console.log("Error :", err);
    }
    // prompt.stop();
  
    function onErr(err) {
      console.log(err);
      return 1;
    }
  }
  
  const downloadFile = async (stage, fileId, finalName, auth) =&gt; {
    const drive = google.drive({ version: "v3", auth });
    console.log(`Downloading ${finalName}`);
    return drive.files
      .get({ fileId, alt: "media" }, { responseType: "arraybuffer" })
      .then(async (res) =&gt; {
        try {
          console.log("Done downloading file.");
          // console.log(res.data);
          // var buffer = new Buffer(res.data, "binary");
          var arrBuffer = res.data;
          var buffer = Buffer.from(new Uint8Array(arrBuffer));
          // console.log("Buffer----", buffer);
          const promise_s3 = await upload_to_s3(
            buffer,
            finalName,
            `migration-temp-${stage}`
          );
          return await promise_s3;
        } catch (err) {
          console.log("Error while uploading", err);
        }
      });
  };</code></pre>
  </div>
  </div>
  </p>
  <p>need help resolving the crash,<br />
  the error - [nodemon] app crashed - waiting for file changes before starting...
  the crash looks like this
  <a href="https://i.stack.imgur.com/CGQvb.png" rel="nofollow noreferrer">Error image</a></p>
  <p>Edit 1 : forgot to mention that i am running it on a t2.large ec2 instance, which has 50GB storage and 8GB RAM</p>