0

I have a problem with executing my node js script. When i run this script normally from command line everything is ok.

enter image description here

But when i want to execute that script directly from django it will print error like this:

enter image description here

the first line says that you are in the code before that line of code what execute that script. Second is path and is correct as you see. Third and to the error are files in that directory (I was checking if executing commands from command line works)

I recall that this django project runs in docker container so i think that error might be there.

Here is my line of code where i run that script in my view.py:

def prepare_log_img(picture):
    string_without_header = re.sub('^data:image/.+;base64,', '', picture)
    img_data = base64.b64decode(string_without_header)
    filename = SITE_ROOT + "/faceId/logged.png"
    with open(filename, 'wb') as f:
        f.write(img_data)
    os.chdir(SITE_ROOT + "/static/scripts")
    print("Pred face detection")
    print(SITE_ROOT + "/static/scripts")
    print(os.system("ls"))
    os.system("node face-detection.js logged.png")

The last line is that executing. Anyone knows what is the problem? Thank you.

1 Answer 1

1

The operating system executing that node face-detection.js logged.png line doesn't know where to go to find your node installation. You can probably fix that by giving the full path to your node installation.

In a regular terminal window type which node, to find out where it is installed, for me the result was /usr/sbin/node. So if I were to run that command it should probably be:

os.system("/usr/sbin/node face-detection.js logged.png")

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your reply. I tried that, but i think that container does not know where is that directory. Because it printed error that it cant find that path where is my node installed. So I think that i must add node.js to the container but idk how :/
Have you access to the Dockerfile for this project? Start with the first line of that docker image as FROM node:9.10, that pulls a base image containing node preinstalled to work from. The only issue is you may be using a django base image already, if that is the case I'm not sure what the best way to install node would be. Shell commands in the dockerfile probably but I don't know much about Docker.
Yes i have access and FROM is only for one entity of project so there i have django and when i add another FROM one will be ignored so it's not a good solution i think, but thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.