1

I'm working on a fun little beginner's project. I am trying to build a face recognition program using node js for my laptop to run upon login. I want it to take a picture whenever someone logs into my laptop and to check the face then I want it to shut down if it's not me. I will use the face-recognition npm package for the recognition part but I can't figure out how to shutdown my computer using javascript. I tried using the child_process package but it doesn't work when I type in exec('shutdown') for some reason. any ideas? (keep in mind I am a newbie so explain it to me like a 5-year-old).

2
  • 1
    Could you edit the question and post what code you have so far? And what operating system are you running this on? Commented Apr 23, 2020 at 0:15
  • 4
    What OS is this? Commented Apr 23, 2020 at 0:28

1 Answer 1

3

As far as I know there is no native way for Node to shut down a computer. However, Node does have the ability to execute shell commands and these shell commands can be used to shut down a computer.

For example,

On Linux shutdown -h now will shut down the computer now.

Using childprocess you can execute the shell command for shutdown.

See here for an example of how these work.

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

Comments

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.