Here is the output of a variety of approaches, the first ones being the best. I don't think you want to stringify the object in routes/index.js, since then you can't mainpulate the data in your helloworld.jade file. So I left index.js as is. views/helloworld.jade:
extends layout
block content
h1= title
p These 2 work and are the same
p #{data.val}
p !{data.val}
p Without the extension returns an object
p #{data}
p !{data}
Trying to stringify almost works except has quotes
p #{JSON.stringify(data)}
p #{JSON.stringify(data.val)}
p !{JSON.stringify(data.val)}
p Trying to set a variable doesn't seem to work at all
script(type='text/javascript').
var newdata = !{JSON.stringify(data)};
p The variable output
p #{newdata}
p bottom of file
script(type='text/javascript').
console.log("testing");
Here is the output:
Hello, World!
These 2 work and are the same
This is a Test
This is a Test
Without the extension returns an object
[object Object]
[object Object]
to stringify almost works except has quotes
{"val":"This is a Test"}
"This is a Test"
"This is a Test"
Trying to set a variable doesn't seem to work at all
The variable output
bottom of file
I couldn't figure out a way to set a variable and display it in the .jade file, but there undoubtedly is a way that I don't know about. Hopefully this helps others that run up against the same issues.