npm post install script does not work with sudo

I need to run a post-install script because a library I am using (elastic.js) is not bundled correctly.

package.json

{
    "name": "xxxxxxx",
    "version": "1.0.0",
    "dependencies": {
        "elastic.js": "fullscale/elastic.js"
    },
    "scripts": {
        "install": "cp node_modules/elastic.js/dist/elastic.js node_modules/elastic.js"
    }
}

When in npm install this on my development machine, it works.

On my production machine, however, all application files are owned by root. When I run sudo npm install there, then the folder node_modules interestingly doesn't belong to root but to my own user that runs the sudo command. Subsequently the install script fails:

npm WARN cannot run in wd xxxxxxx@1.0.0 cp node_modules/elastic.js/dist/elastic.js node_modules/elastic.js (wd=/usr/share/xxxxxxx/app)

But when I issue this exact command it works, both as my user and as root.

So here's the question(s): Why is the directory node_modules not owned by root? And how can I make this post-install script work? Is there a better way to overcome the badly packaged module?