const
carlo
=
require
(
'carlo'
);
(
async
()
=>
{
// Launch the browser.
const
app
=
await carlo
.
launch
();
// Terminate Node.js process on app window closing.
app
.
on
(
'exit'
,
()
=>
process
.
exit
());
// Tell carlo where your web files are located.
app
.
serveFolder
(
__dirname
);
// Expose 'env' function in the web environment.
await app
.
exposeFunction
(
'env'
,
_
=>
process
.
env
);
// Navigate to the main page of your app.
await app
.
load
(
'example.html'
);
})();
<script>
async
function
run
()
{
// Call the function that was exposed in Node.
const
data
=
await env
();
for
(
const
type in data
)
{
const
div
=
document
.
createElement
(
'div'
);
div
.
textContent
=
`
$
{
type
}:
$
{
data
[
type
]}`;
document
.
body
.
appendChild
(
div
);
}
}
</script>
<body
onload
=
"
run
()
"
>
node example.js
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |