Skip to content

DeadmanXXXII/Node.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Node.js

Here's an extensive and detailed list of Node.js CLI commands:

Node.js CLI Commands

1. Node.js Version Management

  • Check Node.js version:

    node -v
  • Check npm version:

    npm -v
  • Update Node.js (using nvm - Node Version Manager):

    nvm install node # Install latest version
    nvm install <version> # Install specific version
    nvm use <version> # Switch to specific version
  • List installed Node.js versions (using nvm):

    nvm ls
  • List available Node.js versions (using nvm):

    nvm ls-remote

2. Node.js Script Execution

  • Run a Node.js script:

    node script.js
  • Run a script with additional arguments:

    node script.js arg1 arg2
  • Run a script with environment variables:

    NODE_ENV=production node script.js
  • Run Node.js in REPL (Read-Eval-Print Loop) mode:

    node
  • Run Node.js with debugging:

    node --inspect script.js

3. npm (Node Package Manager) Commands

  • Initialize a new Node.js project:

    npm init
  • Initialize a new Node.js project with default settings:

    npm init -y
  • Install a package locally:

    npm install package-name
  • Install a package globally:

    npm install -g package-name
  • Uninstall a package:

    npm uninstall package-name
  • List installed packages:

    npm list
  • Update all packages to their latest versions:

    npm update
  • Check for outdated packages:

    npm outdated
  • Check for security vulnerabilities in installed packages:

    npm audit
  • Audit and fix vulnerabilities:

    npm audit fix
  • Generate a package-lock.json file:

    npm install
  • Run scripts defined in package.json:

    npm run script-name
  • View details of a specific package:

    npm view package-name

4. npx (Node Package Runner)

  • Run a package without installing it:

    npx package-name
  • Run a specific version of a package:

    npx package-name@version
  • Run a command from a package:

    npx package-name command

5. Node.js Advanced Commands

  • Run Node.js with V8 Inspector:

    node --inspect-brk script.js
  • Run Node.js with Trace:

    node --trace-warnings script.js
  • Run Node.js with Profiling:

    node --prof script.js
  • Generate a heap snapshot:

    node --inspect script.js

6. Node.js Debugging

  • Start debugging with the inspect flag:

    node --inspect script.js
  • Start debugging with the inspect-brk flag (breaks before user code runs):

    node --inspect-brk script.js
  • Debug in Chrome DevTools: Open chrome://inspect in Chrome and click "Open dedicated DevTools for Node".

  • Debug with Visual Studio Code: Configure .vscode/launch.json and use the "Run and Debug" pane.

7. Node.js Performance Monitoring

  • Measure performance with the built-in profiler:

    node --prof script.js
  • Analyze the generated V8 log:

    node --prof-process isolate-0xnnnnnnnnnnnn-v8.log

8. Node.js Package Development

  • Create a new package template:

    npm init
  • Link a local package for development:

    npm link
  • Publish a package to npm registry:

    npm publish
  • View package publish history:

    npm view package-name
  • Access package information from the npm registry:

    npm info package-name

9. Node.js Testing

  • Run tests defined in package.json (e.g., with Mocha):

    npm test
  • Run tests with a specific framework (e.g., Jest):

    npx jest
  • Run tests with a specific environment variable:

    TEST_ENV=production npx mocha

10. Node.js Code Quality and Linting

  • Run ESLint for linting JavaScript code:

    npx eslint filename.js
  • Fix linting issues automatically:

    npx eslint filename.js --fix
  • Check code formatting with Prettier:

    npx prettier --check filename.js
  • Format code with Prettier:

    npx prettier --write filename.js

11. Node.js Environment Management

  • Set environment variables temporarily:

    ENV_VAR=value node script.js
  • Use .env files with dotenv package:

    npm install dotenv

    In script.js:

    require('dotenv').config();
    console.log(process.env.ENV_VAR);

Summary

This comprehensive list includes fundamental and advanced Node.js CLI commands, package management, debugging, performance monitoring, testing, and code quality tools. It covers common practices for managing Node.js environments, developing and testing applications, and ensuring code quality.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published