Build a Lightweight Invoicing App with Node UI
In this article
You can build a lightweight invoicing app with a Node.js user interface by pairing a minimal Express server with a simple HTML front end and a JSON file for storage. The shortest working path is: create a project folder, run npm init -y, install Express, write a small server that serves a form and saves invoices to a local JSON file, then open http://localhost:3000 in your browser. This guide walks through that build step by step, using only official packages and standard Node.js features, so you end up with a working tool you can extend later.
What You'll Need
- A computer running Windows, macOS, or Linux.
- Node.js installed from the official Node.js website (the LTS version is fine). Installing Node also installs npm.
- A plain text editor or code editor.
- A terminal or command prompt.
- Basic familiarity with JavaScript and HTML helps but is not strictly required.
Step-by-Step
- Create the project folder and initialise it. Open your terminal, create a new folder such as
invoice-app, move into it withcd invoice-app, and runnpm init -y. This creates apackage.jsonfile that tracks your dependencies. - Install Express. Run
npm install express. Express is a small, widely used web framework that handles routing and serving files. You do not need a database package for this build; a JSON file is enough for a lightweight app. - Create the server file. In the project folder, create a file named
server.js. At the top, require Express and the built-infsandpathmodules. Set up the app withconst app = express();and addapp.use(express.json());so the server can read JSON sent from the browser. Addapp.use(express.static('public'));so files in apublicfolder are served automatically. - Create the public folder and the invoice form. Make a folder named
publicinside the project. Inside it, createindex.htmlwith a simple form: fields for client name, invoice number, date, description, quantity, unit price, and a submit button. Add a small script tag at the bottom that sends the form data to the server usingfetchwithmethod: 'POST'andheaders: {'Content-Type': 'application/json'}. Keep the form plain HTML and CSS; no framework is needed for a lightweight app. - Add a route to save invoices. Back in
server.js, addapp.post('/api/invoices', ...). Inside the handler, read the request body, calculate the line total (quantity multiplied by unit price), and push the invoice into an array. Write the array to a file namedinvoices.jsonusingfs.writeFile. Return a JSON response with the saved invoice and a success flag. If the file does not exist yet, start with an empty array. - Add a route to list invoices. Add
app.get('/api/invoices', ...)that readsinvoices.jsonand returns the array as JSON. On the front end, add a button or a page load handler that fetches this route and renders each invoice in a table. Include the client name, invoice number, date, and total. - Start the server and test. Add
app.listen(3000, () => console.log('Running on http://localhost:3000'));at the bottom ofserver.js. Runnode server.jsin the terminal. Openhttp://localhost:3000in your browser, fill in the form, and submit it. Check that the invoice appears in the list and thatinvoices.jsonnow contains the data. - Add a delete option. Add
app.delete('/api/invoices/:id', ...)that filters the array by invoice number or a generated ID and rewrites the JSON file. On the front end, add a delete button next to each row that calls this route and refreshes the list. This keeps the app usable without editing files by hand. - Handle errors and missing files. Wrap file reads and writes in try/catch blocks. If
invoices.jsonis missing or empty, return an empty array instead of crashing. Send a 400 response when required fields are missing, and show a short message in the browser so the user knows what went wrong. - Style and extend only as needed. Add a small CSS file in the
publicfolder to make the table readable. If you want PDF invoices later, look for an official npm package and follow its documentation; do not add features you do not need yet. A lightweight app stays useful because it stays small.
Common Mistakes
- Forgetting
app.use(express.json()), which makes the request body empty and causes the save route to fail silently. - Serving the front end from the wrong folder. The
publicfolder must sit next toserver.js, and the static middleware must point to it. - Writing to
invoices.jsonwithout checking whether the file exists first, which throws an error on the first run. - Using a port that is already in use. If the server fails to start, change 3000 to another number such as 3001.
- Trusting numbers from the form without converting them. Quantity and unit price arrive as strings, so convert them with
Number()before doing maths. - Leaving the JSON file open in an editor while the app writes to it, which can overwrite changes.
Tips
- Keep
invoices.jsonout of version control if you use Git, since it contains client data. - Give each invoice a unique ID at creation time so delete and edit routes are simple to write.
- Round totals to two decimal places before saving to avoid long floating-point values.
- Use
nodemonduring development if you want the server to restart automatically after edits; install it as a development dependency only. - Back up the JSON file regularly. It is the entire database for this app.
- Keep the form and the table on the same page for a lightweight feel; separate pages are fine but add navigation work.
Troubleshooting
If the browser shows a blank page, check the terminal for errors and confirm the server is running. If the form submits but nothing is saved, open the browser developer tools, look at the Network tab, and check the response from the POST request. A 400 response usually means a required field is missing; a 500 response usually means the file write failed, often because of a permissions problem or a malformed JSON file. If the list does not refresh, confirm the GET route returns an array and that the front-end script is reading the right property. If the server will not start, run node server.js directly to see the error message, and check that Express is listed in package.json. If invoices.json becomes corrupted, open it in a text editor, fix the JSON syntax, or replace it with an empty array [] and re-enter the data.
Frequently Asked Questions
Do I need a database for this app?
No. A JSON file is enough for a lightweight invoicing app used by one person. Move to a database only when you need multiple users or large volumes of invoices.
Can I use this app on my phone?
The app runs on your computer and is reached through a browser. Other devices on the same network can open it using your computer's local IP address and the port, but it is not designed for public internet access without extra security work.
How do I add a PDF export?
Look for a maintained npm package that generates PDFs from HTML or data, read its official documentation, and add a route that returns the generated file. Keep the export optional so the core app stays simple.
Is it safe to store client data in a JSON file?
It is acceptable for personal or small-scale use on a trusted computer. Do not expose the app to the public internet without authentication, and back up the file regularly.
Why does the total show many decimal places?
JavaScript uses floating-point numbers. Round the result with Math.round(value * 100) / 100 before saving or displaying it.
Can I edit an invoice after saving it?
Yes, if you add a PUT route that finds the invoice by ID, replaces its fields, and rewrites the JSON file. The same pattern as the delete route applies.