Using JavaScript to extract nutrition facts from recipes

Marcello Barile
The Startup

--

About 3 years ago, I’ve started a side project named “FFaaS — FoodFacts as a Service”; the aim was to create a web-service + a web-app capable of analyzing a recipe, given as an input, and extract some meaningful nutrition data from it.

The kick-off has been pretty fast, in a couple of weeks I managed to have a very first functioning version ready-ish to be used.

And here it is the sketchy UI; only in Italian, float numbers in a pretty ugly format but, hey, it was just a PoC after all… and it had a basic set of functionalities as well:
- selection of foods and quantities w/ auto-suggestion (left panel)
- a list with nutrients and scaled quantities (right side, first panel)
- a list of (healthy) properties associated with the nutrients (right side, last panel)
- excel generation

… and it has remained like this until today.

In the meanwhile, my life got much more intricated; family, hobbies, the fact that I was trying to avoid sitting in front of a PC for 14hours/day… and all my side-projects went in the shady part of my hard-drive :-)

My developer life has always gone through phases; I start a project, I reach a “yeah-its-kindof-working” state, I abandon it, I feel bad and sorry, I grab it again, I refactor it… and like this over and over and over. Does it sound familiar to anyone? :-)

Now I’m in the “yeah-lets-refactor-it!” phase, so I decided to turn this project into an NPM package; in this way, I can still share my efforts with the community but I don’t have to worry about taking care of the server, the UI and everything that orbits around an actual web-app.

The NPM package is available here:
https://www.npmjs.com/package/nutrifacts

Nutrifacts.js is a library to extract and calculate nutrition facts, on several levels of detail; the library is capable of processing natural language strings and retrieving information using precise inputs (IDs or labels). It does work without interacting with 3rd-party services or remote Databases.

And here a couple of examples (if you want to see an example without running the code, just scroll a bit further down):

EDIT: version 1.2 is out… besides some fixes and tweaks, there are new data exposed in the results.

Two examples of the new data

As shown in the pictures above, there are certain nutrients that now have information about their daily intakes and a “health risk ratio” of the given amount (the higher the worst).

In case a whole recipe has been submitted, there will also be a total “health risk ratio” that will represent how healthy is the given recipe (based on the available values in the database).

Disclaimer:

1) This is not a medical software hence the output should NEVER replace the advice of a professional nutritionist.

2) At the moment there are some crucial TODOs (that you can find here if interested); since food and nutrition have to be taken seriously, I would also love some help from nutritionists, especially for tweaking and improving the properties associated with nutrients.

If you want to explore the API of the library, just check the GitHub repo here.
Any contribution is accepted and welcomed :-)

Well, at this point, thanks for having reached the bottom and see you around.
Eat well and enjoy your day!

--

--

Marcello Barile
The Startup

A computer scientist who works on a daily basis with TypeScript and Node.js, passionate about Computer Vision and Robotics.