Sudden high memory usage

I updated a resolution constant for my discord bot earlier for some web screenshoter using the nodejs module webshot. Then memory usage skyrocketed to a peak of 2gb and the glitch project started a series of restarts because of memory.
So then I completed commented out the web screenshoting part of my bot and it is still running out of memory every time it starts. I can’t post all of my code but I can post snippets of it.

// Package.json
  "name": "Ascension",
  "version": "0.0.2",
  "description": "An amazing bot",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  "dependencies": {
    "express": "^4.17.1",
    "discord.js": "^11.5.2",
    "dotenv": "^8.2.0",
    "ytdl-core": "^2.0.0",
    "subtitles-parser": "^0.0.2",
    "node-opus": "^0.3.2",
    "yt-xml2srt": "^1.1.0",
    "phantomjs-prebuilt": "^2.1.1",
    "mathjs": "^6.6.1",
    "sodium": "^3.0.2",
    "bufferutil": "^4.0.1",
    "zlib-sync": "^0.1.6",
    "erlpack": "^0.1.3",
    "opusscript": "^0.0.7"
  "engines": {
    "node": "8.x"
  "repository": {
    "url": "!/template-discord-bot"
  "license": "MIT",
  "keywords": [

Yes, I used a template from somewhere

// Server.js part 1
// Reset
// Create some constant values...
const discord = require("discord.js");
const bot = new discord.Client();
const dotenv = require("dotenv");
const fs = require("fs");
const ytdl = require("ytdl-core");
const path = require("path");
const https = require("https");
const parser = require("subtitles-parser");
const { evaluate,parse} = require('mathjs')
const {createEmbed} = require("./embeds")
const mathQuestion = require("./math");
var difficulty = "super-easy";
var curMSG; // Restart required
const storeData = (data, path) => {
  try {
    fs.writeFileSync(path, JSON.stringify(data));
  } catch (err) {
const loadData = path => {
  try {
    return fs.readFileSync(path, "utf8");
  } catch (err) {
    return false;

Part 2:

// Server.js part 2
// Load from the .env file
console.log("ENV Set");
console.log("Loading db");
var db = loadData("database.json");
var keys = Object.keys(db);
if (!("test" in keys)) {
  console.log("Creating test");
  db["test"] = {};
// Grab the bot token from the .env file
console.log("Got token");
const botToken = process.env.BOT_TOKEN;

Lots of event handler and bot code after that
Part 3:

// server.js part 3
// End of bot.on('message')
console.log("Cleanup handlers");
process.stdin.resume(); //so the program will not close instantly

function exitHandler(options, exitCode) {
  // Cleanup here
  console.log("Cleaning Up");
  storeData(db, "database.json");
  if (options.cleanup) console.log("clean");
  if (exitCode || exitCode === 0) console.log(exitCode);
  if (options.exit) process.exit();

//do something when app is closing
process.on("exit", exitHandler.bind(null, { cleanup: true }));

//catches ctrl+c event
process.on("SIGINT", exitHandler.bind(null, { exit: true }));

// catches "kill pid" (for example: nodemon restart)
process.on("SIGUSR1", exitHandler.bind(null, { exit: true }));
process.on("SIGUSR2", exitHandler.bind(null, { exit: true }));

//catches uncaught exceptions
process.on("uncaughtException", exitHandler.bind(null, { exit: true }));
// Since there is no actual preview for the bot (unless you add your own website code)
// It will be an error or continious refresh loop, consider this part of the code that keeps the bot alive
// Though you will still need an uptime robot in order to truely keep the bot alive
// This is NOT my code, the code is directly from this page:
console.log("Start self server");
const http = require("http");
const express = require("express");
const app = express();
app.get("/", (request, response) => {
  console.log( + " Ping Received");
setInterval(() => {
}, 280000);

// Bot token
// Located in .env file

Have you tried the following?

git prune

Followed by:

git gc 

Or, alternatively:

rm -rf .git

@Warriorfoox You should give a heads up if you ever suggest running that last command. People might not realize it will wipe their entire project history.

@javaarchive, is your database.json file large? By the way, I love the handlers.

no i actually never figured out how to work the database. Wait it is large
Running ls -l database.json
-rw-r--r-- 1 app app 16777216 Mar 10 05:08 database.json
It is 16mb, so I’m not sure why gltich can’t open it. I’ve deleted it and everything is fixed. Thanks a everyone.
I’ll make a new post asking how to the database later or maybe I’ll switch to endb

Huh, I’m glad that fixed it.

I’ll make a new post asking how to the database later or maybe I’ll switch to endb

What is it with endb? It’s the package someone on these forums made, right?

Right. You can find it at this website