-1

is it possible to restart computer using nodejs? I've searched whole day but I still have no idea how to do it or is it possible. Maybe I can make restart.bat and run it in my js program? I'm grateful for any piece of code, idea, recommendation or anything. Thank you!

Srki
  • 315
  • 1
  • 4
  • 13

1 Answers1

2

As far as I am aware, there is no node feature to shutdown or restart the computer. However, node is able to run shell commands.

shutdown -h now is the command on linux.

You would use childprocess (here) to shut it down on Windows.

What is the reason you are looking to shut it down? There may be more effective methods depending on situation and reason.

alien_jedi
  • 306
  • 3
  • 11
  • I'm making small quiz for my school project. In case you guess incorrectly, your computer will restart itself and you must start all over again. It's just for fun. – Srki Apr 13 '22 at 22:37
  • 2
    @Srki, that is not fun, it is potentially data destructive. – Compo Apr 13 '22 at 22:51
  • @Compo It's just for school project. I'll be running it on my laptop so if something happens it's all my fault. – Srki Apr 13 '22 at 22:53