Checkout this video:
To use the node command, you will need to type “node” followed by the name of your file. So, if your file is named “script.js”, you would type “node script.js” into the terminal.
For example, if your file is called “hello.js”, you would use the following command to run it:
1. Download and install node.js from https://nodejs.org/en/.
2. After installing node.js, open your Terminal/Command Prompt and type “node -v”. You should see the installed node.js version number printed on the screen.
-SyntaxError: The most common error when running JS code, a SyntaxError occurs when the JS interpreter encounters code that it cannot understand. This can be due to incorrect syntax, or an unsupported feature being used.
-ReferenceError: A ReferenceError occurs when the JS interpreter encounters a reference to an undefined variable.
-TypeError: A TypeError occurs when a value is used in an unexpected way. For example, trying to use a string as a number, or calling a function that does not exist.
First, make sure that you are in the correct directory when you try to run the file. If you’re not sure which directory you’re in, you can use the ‘pwd’ command to print the current working directory.
Next, check that the file exists in the current directory by using the ‘ls’ command to list all of the files and directories in the current working directory. If the file you’re trying to run doesn’t appear in the list, it’s likely that it’s not in the current directory.
If the file does exist but you’re still having trouble running it, make sure that it has executable permissions by using the ‘ls -l’ command to list all files and directories in the current working directory with their permissions. Executable files will have an ‘x’ in the permissions column. If the file doesn’t have executable permissions, you can use the ‘chmod +x’ command to add executable permissions.