CoolProp on Node.js server

367 views
Skip to first unread message

Viktor De Knibber

unread,
Feb 24, 2021, 2:41:26 AM2/24/21
to coolprop-users
Hi,

The CoolProp JavaScript wrapper was very easy to implement on a simple html file with the wrapper as script, which made me think that I would be able to make it work just as easily on a Node.js server. I was wrong, or I'm simply not doing all the required steps.

How would I go about integrating CoolProp on a Node.js/Express server (preferably also in development environment)?
I had assumed a simple import (using the require function) would do it, but when I tested that, I found out that the PropsSI function is undefined.
There are no matches in the JavaScript wrapper for "PropsSI", so I'm assuming it is added with the .wasm file.

I have seen this question pop up only twice (as in: "Is there any example code?"), once on GitHub and once on Google groups. There was no concrete answer given/available, so I'll have to try to make it work myself, but I need some help.
I just need a pointer on what needs to be done in order for it to work, as for right now, I have no clue on where I should start on this.
I'm assuming I need to use the JavaScript wrapper for this (including the .wasm file).

Thank you very much in advance!

Viktor

Ian Bell

unread,
Feb 24, 2021, 6:55:42 PM2/24/21
to coolpro...@googlegroups.com
Hi Viktor,

Sorry, but I'm not a js/node.js person, so I have really no idea.  I think you might also be able to find some joy with http://swig.org/Doc3.0/Javascript.html (we use SWIG for many of the other wrappers), which makes me think you might be able to get that to work without TOO much pain.

Good luck,
Ian

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coolprop-users/c45e9182-30f0-42e4-bfea-ed1b99a31192n%40googlegroups.com.

Viktor De Knibber

unread,
Aug 4, 2022, 11:51:21 AM8/4/22
to coolprop-users
Hi,

Just wanted to tune in that I managed to work it out and wanted to share for potentially other people struggling with it.

I had previously just accessed CoolProp client-side, which was easy enough. However, as my application is getting bigger, I wanted to move the calculations server-side.
I re-tested CoolProp on my Node.js server and I feel extremely stupid as it's probably the easiest and most straight forward way to do it, yet I couldn't find it previously.

Using Node.js and an Express server, I created a test setup that worked perfectly.

This is my router:

const express = require('express');
const cp = require('../coolprop/coolprop');

const router = express.Router();

router.get('/', async (req, res) => {
    res.status(200).json({ val: cp.PropsSI('T', 'P', 101325.0, 'Q', 0.5, 'Water') });
});

module.exports = router;

Front-end is a React application with Axios for data fetching; this is the page component:

import axios from 'axios';
import { useState, useEffect } from 'react';

const TestPage = () => {
    const [data, setData] = useState('');

    useEffect(() => {
        const fetchData = async () => {
            try {
                const res = await axios.get('/api/test');
                setData(res.data.val);
            } catch (err) {
                console.log(err);
            }
        };
        fetchData();
    }, []);

    return (
        <div>
            <h3>CoolProp</h3>
            <p>{data}</p>
        </div>
    );
};

export default TestPage;

As you can see, it's as easy as can be.
Hopefully this can be of use for someone someday.

Massive thanks to Ian for all his work on the CoolProp project!

Kind regards,
Viktor
Op donderdag 25 februari 2021 om 00:55:42 UTC+1 schreef ian.h...@gmail.com:

Joseph Harrison

unread,
Jun 26, 2023, 8:44:42 AM6/26/23
to coolprop-users
I was able to build the coolprop.js via the docker build.

I do not see PropSI function in the coolprop.js file though.  

What am I not doing correctly?

Ian Bell

unread,
Jun 26, 2023, 9:18:44 PM6/26/23
to coolpro...@googlegroups.com
I build the .wasm and .js with the docker build (docker-compose up --build) and run this in the shell: python -m http.server 

Went to localhost:8000 in the browser, worked fine

Craig Zych

unread,
Feb 18, 2025, 7:02:17 PMFeb 18
to coolprop-users
I know this is an old question but hopefully this helps someone. 
I tried making this work unsuccessfully many times and took a stab at it every once in a while. 

I finally figured it out and built a quick wrapper to make the basic functionality for Refrigerant calculations much easier. Theres also direct access to the under lying PropsSI if needed.

https://www.npmjs.com/package/coolprop-node

Unlike the other coolprop libraries on npm it actually works 

Ian Bell

unread,
Feb 19, 2025, 6:46:41 PMFeb 19
to coolpro...@googlegroups.com
Thanks Craig! My only quibble is that I strongly recommend the use of base SI units; it avoids large classes of unit conversion errors.

Craig Zych

unread,
Feb 19, 2025, 10:58:02 PMFeb 19
to coolpro...@googlegroups.com
Are you referring to actually using the base SI units when working directly with coolprop? If so, all function calls to the underlying CoolProp is pre converted to K and PA, then converted back as needed (don't need to convert the deltas)

I needed CoolProps to work in node, but for the rest of my development team I wanted a super simplified method to calculate Superheat and Subcooling using the units of the controllers we work with so I built in a conversion, and set the default units to our needs.

You can still set the superheat and subcooling to K and PAa (atmospheric) and it will directly pass it

Ian Bell

unread,
Feb 20, 2025, 6:19:01 PMFeb 20
to coolpro...@googlegroups.com
I meant your use of bar and celsius. That is fine for simple things, but as you get into more complex calculations, I have found that it is the source of some subtle bugs - the one that keeps biting me is when you have kinetic contributions (v^2/2) and enthalpy contributions. The unit conversion there is not obvious. Since I now do everything in base-SI units, no more problems with units ever again. 

Craig Zych

unread,
Feb 20, 2025, 6:23:07 PMFeb 20
to coolpro...@googlegroups.com
Fair

I tried to make the simple calculations for superheat and subcooling easy but for anything more complex atleast you can directly access the underlying PropsSI directly in node which I was never able to get working before

Ian Bell

unread,
Feb 20, 2025, 6:24:51 PMFeb 20
to coolpro...@googlegroups.com
Thanks for getting this working. Want to write a page of docs describing what you did? I could imagine it would be useful for others.

Craig Zych

unread,
Feb 20, 2025, 6:26:43 PMFeb 20
to coolpro...@googlegroups.com
You can just npm install the module as is and use it without having to mess with anything 
It’s fully documented in the repo

Ian Bell

unread,
Feb 20, 2025, 6:29:37 PMFeb 20
to coolpro...@googlegroups.com
It would also be interesting if you could add a line or two about how you get your package into their package database in the README of your git repo

Craig Zych

unread,
Feb 21, 2025, 12:12:39 PMFeb 21
to coolprop-users
There is an installation section in the readme. 

npm install coolprop-node

Ian Bell

unread,
Feb 21, 2025, 7:37:08 PMFeb 21
to coolpro...@googlegroups.com
Yeah I'm thinking about the other half - how to get your package into npm in the first place

Craig Zych

unread,
Mar 6, 2025, 4:50:32 PMMar 6
to coolprop-users
Thats all searchable but when you create a package, you just run npm publish in the terminal, it'll open a browser to login, then once you authenticate it will publish directly to the repo

Ian Bell

unread,
Mar 6, 2025, 5:54:48 PMMar 6
to coolpro...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages