I am in the process of making a discord bot. All of the code that I have written for the bot works except for the batch file that is supposed to run it. Originally I was just using the node
command and when I opened cmd, navigated to the folder, and typed it manually it worked fine, but when I put that same code into a batch file it gave me this error:
'node' is not recognized as an internal or external command, operable program or batch file.
This is all the code for that batch file:
@echo off
node bot.js
pause
The node command was in my path so I'm not sure why it wasn't working, but in another post, someone recommended that instead of typing just node
to type the full file path, so I tried this and it worked.
Here is the new working code:
@echo off
"C:\Program Files\nodejs\node.exe" bot.js
pause
Then I installed nodemon. Again this works in the cmd when I navigated to the folder and typed it manually, but when I try to do it in the batch file it does not work. Instead of giving me the error it had been before the window just instantly closes. Here is that code:
@echo off
nodemon bot.js
pause
Since I have the pause command at the end of the code it should stop there if I get an error, but it is closing before it gets there for some reason. The nodemon
command is in my path and I have also tried replacing nodemon
with the file path, C:\Users\tdkni\AppData\Roaming\npm\nodemon.cmd
, like I was recommended in the previous post. Neither of these solutions worked, and I think that is because there is some other problem besides the nodemon
command not being detected. I don't see any error message since it is closing instantly so I don't know exactly what is wrong.
The registration of the file extensions .bat
and .cmd
is as follows according to an advice in a comment deleted in the meantime.