In this post, I’m not going to talk about npm (except for the initialisation part), but about how to code your module with Haxe.
First thing to do is to create our npm project.
npm init --yes
--yes because I’m lazy and I don’t want to enter the default value for each prompt.
My default package.json file looks like:
files parameter will tell npm which file/directory to import while installing the module. I only specify the dist directory, because for a production usage, the Haxe sources are not needed. But still, if you want to publish everything, just forget about the
My project looks like:
- test-node-package - dist - index.js - src - Main.hx - package.json - build.hxml
Now that we have our project setup, we can start working on our module.
Let’s say we want to do the following in another project:
In Haxe you will have to:
You will probably need to use the nodejs lib, so don’t forget to add it in your build.hxml: