Installing Node.js and Using the Node CLI
The node command is the primary CLI for executing JavaScript files and interacting with the Node.js runtime. You can verify your installation using node --version and npm --version.
Node also provides a REPL, which is useful for experimenting with JavaScript and Node APIs interactively.
Use a Version Manager
Using a Node.js version manager such as nvm makes it easier to switch between Node.js versions for different projects.
Node.js CLI Basics
node --version
npm --version
node
node app.js💡 The first two commands display installed versions,
node starts the REPL, and node app.js executes a JavaScript file.Key Takeaways
- Use
node filename.jsto execute a Node.js application. - The Node REPL is useful for quickly testing JavaScript expressions.
- Keep project Node.js versions consistent across development and production.
Knowledge Check
Which command executes `server.js`?