I am facing one issue. I need to append \n
inside file using node js fs module
. I am explaining my code below.
let endStr = ' ret= sh(script:"touch robot-rfs.yml && rm -rf robot-rfs.yml ")\n'
+ 'nedarray = list_of_neds.split("\n")';
fs.writeFileSync(`${process.env['root_dir']}/uploads/Jenkinsfile`, endStr);
Here my expected output should be like below after file writing.
Jenkinsfile:
ret= sh(script:"touch robot-rfs.yml && rm -rf robot-rfs.yml ")
nedarray = list_of_neds.split("\n")
But I am getting the output like below.
ret= sh(script:"touch robot-rfs.yml && rm -rf robot-rfs.yml ")
nedarray = list_of_neds.split("
")
Here due to \n
inside split
its taking to new line. I need to write with \n
without any line break inside the file means nedarray = list_of_neds.split("\n")
should be written directly in the file. Can anyone give the help to resolve this issue ?