Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Running JavaScript Files | Running Code and Working with the Node Environment
Node.js Foundations

bookRunning JavaScript Files

12
// hello.js console.log('Hello, Node.js!');
copy

When you execute a JavaScript file with Node.js, you are telling Node.js to read the file, interpret its contents, and run any code written inside. The process starts when you type the node command followed by the filename in your terminal. Node.js loads the specified file, parses the JavaScript code, and executes it line by line in a Node environment. In the example above, Node.js finds the console.log statement and prints the message to your terminal. Once all code in the file finishes running, Node.js ends the process.

Note
Study More

How does Node.js handle errors when running scripts?

Node.js handles errors during script execution by printing error messages to the console. If your code throws an error, Node.js describes the error type, the message, and where it occurred in your file. You can learn more by reading about Node.js error handling in the official documentation.

question mark

Which of the following best describes what happens when you run a JavaScript file with Node.js?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain what the Node environment is?

What happens if there is an error in the JavaScript file?

How is this different from running JavaScript in a browser?

Awesome!

Completion rate improved to 9.09

bookRunning JavaScript Files

Deslize para mostrar o menu

12
// hello.js console.log('Hello, Node.js!');
copy

When you execute a JavaScript file with Node.js, you are telling Node.js to read the file, interpret its contents, and run any code written inside. The process starts when you type the node command followed by the filename in your terminal. Node.js loads the specified file, parses the JavaScript code, and executes it line by line in a Node environment. In the example above, Node.js finds the console.log statement and prints the message to your terminal. Once all code in the file finishes running, Node.js ends the process.

Note
Study More

How does Node.js handle errors when running scripts?

Node.js handles errors during script execution by printing error messages to the console. If your code throws an error, Node.js describes the error type, the message, and where it occurred in your file. You can learn more by reading about Node.js error handling in the official documentation.

question mark

Which of the following best describes what happens when you run a JavaScript file with Node.js?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1
some-alt