N
N
NkDev2022-02-22 16:54:57
JavaScript
NkDev, 2022-02-22 16:54:57

How to pass multiline argument in node.js?

<?php

$var = "Hello
World";

exec('node ../app/node/script.js ' . $var, $output);

echo $output; // Выводит 'Hello'
?>


Content of script.js: That is, only the first line gets into the argument. How to pass a multiline argument there?

console.log(process.argv[2])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Goretsky, 2022-02-22
@NkDev

Instead of double quotes, use reverse single quotes - located on the keyboard where the letter Y is
. As a bonus, the interpretation of variables in the string

let myVar = "строка";
const stroka = `Hello
${myVar}
World`;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question