reply View all Tutorials & Projects

Build a Budget Tracker with JavaScript & Local Storage

In this tutorial we'll be building a Budget Tracker (or Planner) using HTML, CSS & JavaScript. This is easily done using JavaScript Classes and the Import/Export syntax.

Video Tutorial

Source Code

You can find the source code for this video below. Alternatively, browse it on GitHub.

index.js
const express = require("express");
const fileUpload = require("express-fileupload");
const pdfParse = require("pdf-parse");

const app = express();

app.use("/", express.static("public"));
app.use(fileUpload());

app.post("/extract-text", (req, res) => {
    if (!req.files && !req.files.pdfFile) {
        res.status(400);
        res.end();
    }

    pdfParse(req.files.pdfFile).then(result => {
        res.send(result.text);
    });
});

app.listen(3000);
package.json
{
  "name": "extract-pdf-text",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "express-fileupload": "^1.2.1",
    "pdf-parse": "^1.1.1"
  }
}
public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="file" id="inpFile">
    <button type="button" id="btnUpload">Upload</button>
    <br>
    <br>
    <textarea style="width: 300px; height: 150px;" id="resultText" placeholder="Your PDF text will appear here..."></textarea>
    <script>
        const inpFile = document.getElementById("inpFile");
        const btnUpload = document.getElementById("btnUpload");
        const resultText = document.getElementById("resultText");

        btnUpload.addEventListener("click", () => {
            const formData = new FormData();

            formData.append("pdfFile", inpFile.files[0]);

            fetch("/extract-text", {
                method: "post",
                body: formData
            }).then(response => {
                return response.text();
            }).then(extractedText => {
                resultText.value = extractedText.trim();
            });
        });
    </script>
</body>
</html>

If you have any questions about this code, please leave a comment on the video.