Home > Back-end >  how to include python files in node js build
how to include python files in node js build

Time:05-30

I'm stumped here...

I have a node server that calls to a python file for some quick data processing using the spawn approach (How to call a Python function from Node.js) ...and I got it working from the npm CLI.

The issue now is, when actually running the server, the .py file is not being included in the build. So __dirname at runtime is based within the dist folder, and running npm build never copies the .py file into the dist folder.

There's got to be a way to include the python file, right? I tried editing package.json's files field with no luck.

CodePudding user response:

I ended up adding a script to package.json that does the copy, and including it as part of the build script:

...
"build": "nest build && npm run cp:py",
"cp:py": "cp -n src/python/*.py dist/python"
...
  • Related