n8n automatically checks on every startup if there are any npm packages installed that have n8n nodes defined and if so it loads them automatically. So all the logic you need is already in place to do what you want to do.
You can find the code for an example npm module for an external n8n node here.
You can find some information about that in the documentation here.