DEV Community

Njiva Olaf { dev-it-out }
Njiva Olaf { dev-it-out }

Posted on • Updated on

Building a simple invoice generator with Node Js

Why β“πŸ€”

After each online coaching sessions, at the beginning, that was a pain to find a good invoice generator platform as I was not yet ready for a 20€ monthly subscription just for handling the invoice part.

None was enough flexible for my own use πŸ™„ so.. I decided to build my own mini-invoice generator with Node Js βœ… ( that took approx 1h max βŒ›οΈ )

No more talk..Straight to the point πŸ’ͺ🏼

The main parts βš™οΈ:

1. Storing clients in Json :

Yep that one is simple..for now x)

(Note: these are fictional characters of course 😝 )

Image description

2. Creating the route:
Using express router, just create a POST /invoice route.
const router = express.Router();
router.post('/', handleCreateInvoice);

Then add the Joi Schema. Why ? It allows to define schema and validate the schema before calling the controller/handler of invoice creation.

Source: https://joi.dev/

Image description

3. Handling the invoice creation:

I used the module pdf-kit to generate the pdf to be sent to the client.

pdf-kit

Image description

4. Email sending:
A small function using gmail-send npm module which accepts html as an input Image description

Yep..so what about the result ?

A snapshot of my first trials ^^ ( yep that email should be more personnalized and better structure 😊 )

Insomnia POST Call
Image description

Final result 😁
Image description

The pdf:
Image description

Next steps:

  • Front-end ( React πŸ€” )
  • Database πŸ’Ώ
  • make it online x)
  • Iterate πŸ‘€

And you πŸ’ͺ🏼?

Tell us in the comments which mini-project you built πŸ‘€πŸ˜Š

Wanna support me ?

I am blogging during my free time ^^ like most people on this platform 😊 however I'm not against a small coffee if you want to support me πŸ’ͺ🏼 Link below:

https://ko-fi.com/dev_it_out

P.S: I added the sample on Github ( https://github.com/njivaolafpro/invoice-management-sample

Discussion (23)

Collapse
laurencioscript profile image
Gabriel Laurencio

i built a mini project for knowing new chapters of mangΓ‘s in site and warn in my channel in discord when has new releases, basically my project did web scraping in specific web page.

github.com/laurencioScript/sakamot...

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

nice ^^ would love having an english version of the README though :/

Collapse
andrewbaisden profile image
Andrew Baisden

Cool project.

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

thanks ^^ was just a small hobby ^^

Collapse
cjw profile image
Clifford Watson

good read

Collapse
aaravrrrrrr profile image
Aarav Reddy

Thanks for writing

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

no prob ;)

Collapse
leanderd profile image
Leander Dirkse • Edited on

You could try to connect it to Toggl Track via their API.
Keep track of time, projects, clients etc.

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

Good idea ^^ will try that one ;) thanks

Collapse
kelseyjj profile image
Kelsey Jones

Awesome article.

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

thank you ^^

Collapse
warwait profile image
Parker Waiters

Glad I came across this.

Collapse
felipegenuino profile image
Felipe Genuino

Nice work

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

thanks x)

Collapse
umeya_kassim profile image
umeya kassim

How does one know the right library to use in this case of generation

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

for the pdf generation, there are some on npm, I usually use the most stable with a good community ;)
( I tend to avoid html -> pdf as there are some bugs in the zooming part )

Collapse
juanfabiorey profile image
juanfabiorey

Wow! Thanks

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

no prob ;)

Collapse
cednore profile image
Y2Vkbm9yZQ==

So Nice!

Collapse
adarshmadrecha profile image
Adarsh Madrecha

Any link to the code?
Can you please share a sample PDF.

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

yep...I just edited the post to add the github link.

github.com/njivaolafpro/invoice-ma...

Collapse
bam92 profile image
Abel Lifaefi Mbula

A good short that goes straight to the main point. Hope you'll open source the project.

Collapse
olaf_ranai profile image
Njiva Olaf { dev-it-out } Author

thanks ^^
It is on git

github.com/njivaolafpro/invoice-ma...
( need to clean up a bit the doc though ;) )