Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

43
Vistas
Run js string as argument from command line

I did search for this topic for at least half an hour, but all I could find was how to run script inside a js-file:

$ node foo.js

But what if I wanted to execute a string provided as an argument? The following won't work:

$ node "console.log('hi')"
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '/Users/hans/console.log('hi')'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v17.3.0
7 months ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos