I want to make a script that will treat \n character as a literal new line character when given as command line argument. For example if my script is test.js, I want to use node test.js 'Line 1\nLine 2' and get the output as:
Line 1
Line 2
The script I used to test if this works was:
console.log(process.argv[2]);
But when I used it like node test.js 'Line 1\nLine2', it gave me the output as:
Line 1\nLine2
How do I achieve this?
console.log('line 1\nline 2');prints exactly what you want.