diff --git a/src/node_dotenv.cc b/src/node_dotenv.cc
index 8d92e917082488..a10b0d27186178 100644
--- a/src/node_dotenv.cc
+++ b/src/node_dotenv.cc
@@ -18,8 +18,8 @@ using v8::String;
  */
 const std::regex LINE(
     "\\s*(?:export\\s+)?([\\w.-]+)(?:\\s*=\\s*?|:\\s+?)(\\s*'(?:\\\\'|[^']"
-    ")*'|\\s*\"(?:\\\\\"|[^\"])*\"|\\s*`(?:\\\\`|[^`])*`|[^#\r\n]+)?\\s*(?"
-    ":#.*)?");  // NOLINT(whitespace/line_length)
+    ")*'|\\s*\"(?:\\\\\"|[^\"])*\"|\\s*`(?:\\\\`|[^`])*`|[^#\r\n]+)?\\s*");
+     // NOLINT(whitespace/line_length)
 
 std::vector<std::string> Dotenv::GetPathFromArgs(
     const std::vector<std::string>& args) {
@@ -104,6 +104,7 @@ Local<Object> Dotenv::ToObject(Environment* env) {
 void Dotenv::ParseContent(const std::string_view content) {
   std::string lines = std::string(content);
   lines = std::regex_replace(lines, std::regex("\r\n?"), "\n");
+  lines = RemoveComments(lines);
 
   std::smatch match;
   while (std::regex_search(lines, match, LINE)) {
@@ -126,7 +127,7 @@ void Dotenv::ParseContent(const std::string_view content) {
     }
 
     // Remove surrounding quotes
-    value = trim_quotes(value);
+    value = TrimQuotes(value);
 
     store_.insert_or_assign(std::string(key), value);
     lines = match.suffix();
@@ -179,7 +180,7 @@ void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) {
   }
 }
 
-std::string_view Dotenv::trim_quotes(std::string_view str) {
+std::string_view Dotenv::TrimQuotes(std::string_view str) {
   static const std::unordered_set<char> quotes = {'"', '\'', '`'};
   if (str.size() >= 2 && quotes.count(str.front()) &&
       quotes.count(str.back())) {
@@ -188,4 +189,22 @@ std::string_view Dotenv::trim_quotes(std::string_view str) {
   return str;
 }
 
+std::string Dotenv::RemoveComments(const std::string& content) {
+    std::istringstream iss(content);
+    std::string result;
+    std::string line;
+
+    while (std::getline(iss, line)) {
+        if (line.empty()) {
+            continue;
+        }
+        // Trim leading whitespace and check if the line starts with '#'
+        std::string trimmed = line.substr(line.find_first_not_of(" \t"));
+        if (trimmed.front() != '#') {
+            result.append(line + "\n");
+        }
+    }
+    return result;
+}
+
 }  // namespace node
diff --git a/src/node_dotenv.h b/src/node_dotenv.h
index 5872627f0c25fe..a9e6df5658ccdf 100644
--- a/src/node_dotenv.h
+++ b/src/node_dotenv.h
@@ -32,7 +32,8 @@ class Dotenv {
 
  private:
   std::map<std::string, std::string> store_;
-  std::string_view trim_quotes(std::string_view str);
+  std::string_view TrimQuotes(std::string_view str);
+  std::string RemoveComments(const std::string& str);
 };
 
 }  // namespace node
diff --git a/test/fixtures/dotenv/valid.env b/test/fixtures/dotenv/valid.env
index ccffa779cb0d86..522e49cdba8ade 100644
--- a/test/fixtures/dotenv/valid.env
+++ b/test/fixtures/dotenv/valid.env
@@ -24,6 +24,8 @@ EXPAND_NEWLINES="expand\nnew\nlines"
 DONT_EXPAND_UNQUOTED=dontexpand\nnewlines
 DONT_EXPAND_SQUOTED='dontexpand\nnewlines'
 # COMMENTS=work
+#BASIC=basic2
+#BASIC=basic3
 INLINE_COMMENTS=inline comments # work #very #well
 INLINE_COMMENTS_SINGLE_QUOTES='inline comments outside of #singlequotes' # work
 INLINE_COMMENTS_DOUBLE_QUOTES="inline comments outside of #doublequotes" # work
@@ -37,7 +39,7 @@ TRIM_SPACE_FROM_UNQUOTED=    some spaced out string
 EMAIL=therealnerdybeast@example.tld
     SPACED_KEY = parsed
 EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3"
-
+export EXAMPLE = ignore export
 MULTI_DOUBLE_QUOTED="THIS
 IS
 A
@@ -58,4 +60,3 @@ STRING`
 MULTI_NOT_VALID_QUOTE="
 MULTI_NOT_VALID=THIS
 IS NOT MULTILINE
-export EXAMPLE = ignore export