Nathan Arcuri
Portfolio • Projects • Experiments

DreamLog - Browser Based Dream Journal (Node.js)

A node server enabled, browser based dream journal and assessment tool.

Javascript Node Server

← Back to Projects

Dream Log

overview

About the project

Have you ever had such incredibly vivid and strangely relevant dreams? I began having strange dreams and decided I wanted to remember them and pull meaning from them, but I didn't want to write them down or simply type them into a notepad. What I decided to do was make a Node-powered, browser-based dream journal app.


Goal

To make an app that allows the user to name their dream, enter the date they had the dream, and describe the dream. Once submitted, the dream is added to a txt file in a dream log folder. The user can also select the "Dream Log" link from the web UI and see their past submissions. While reviewing past submissions, the user can assess their dreams by asking themselves probing questions about their dream.


What I learned

  • - How to build a full stack app with Node backend and browser frontend
  • - Learned API handling, file storage, and basic app architecture
  • - Improved UX thinking with forms, validation, and data flow
  • - How to turn a personal need into a working tool

Project

A browser based dream journal app that lets users name a dream, enter the date, describe it, save entries as local text files, review past dreams through the web UI, and add later reflections for deeper analysis.

How It Works

logic
  1. User enters a dream title, date, and description in the web form.
  2. The browser sends the entry to the Node backend through an API request.
  3. The server formats the entry and saves it as a text file in the Dream Log folder.
  4. The Dream Log page loads existing entries so past dreams can be reviewed.
  5. Users can add later reflections or assessments to expand on saved dreams.

Screenshots

preview

Code Snippets

design

This is the main backend endpoint. It receives dream data from the browser, validates it, sanitizes the filename, prevents duplicates, formats the dream into readable text, and saves it to a .txt file. This shows full stack integration, validation, filesystem use, and structured output:

Node.js

app.post("/api/dreams", async (req, res) => {
  try {
    ensureDreamDirSync();

    const { name, date, details } = req.body || {};

    if (!name || !date || !details) {
      return res.status(400).json({ error: "Missing name, date, or details." });
    }

    if (!isValidDateMMDDYYYY(date)) {
      return res.status(400).json({ error: "Date must be valid and formatted MM-DD-YYYY." });
    }

    const safeName = sanitizeDreamNameForFilename(name);
    if (!safeName) {
      return res.status(400).json({ error: "Dream name invalid after sanitizing." });
    }

    const fileDate = toFilenameDate(date);
    const filename = `${fileDate}_${safeName}.txt`;
    const fullPath = safeResolveDreamPath(filename);

    if (fs.existsSync(fullPath)) {
      return res.status(409).json({ error: "Dream already exists." });
    }

    const content = formatDreamFile(date, name.trim(), String(details).trim());
    await fsp.writeFile(fullPath, content, "utf8");

    res.json({ ok: true, filename });
  }
  catch (err) {
    res.status(500).json({ error: err.message });
  }
});

This prevents security issues like writing files outside the intended folder. It normalizes the path and ensures everything stays inside the Dream Log directory:

Node.js

function safeResolveDreamPath(filename) {
  const full = path.join(DREAM_DIR, filename);
  const normalized = path.normalize(full);

  if (!normalized.startsWith(path.normalize(DREAM_DIR + path.sep))) {
    throw new Error("Invalid path.");
  }

  return normalized;
}

This function standardizes how dreams are saved. It ensures consistent formatting for readability and easy manual review:

Node.js

function formatDreamFile(dateMMDDYYYY, title, body) {
  return `[--------------DREAM LOG--------------]
--${dateMMDDYYYY}--
--${title}--

${body}

[-------------------------------------]
`;
}

Files

downloads

Possible Improvements

next steps
  • - Implement an LLM API feature so that the user's dreams can be assessed by an AI.

← Back to Projects