Node.js express rendering inside included js files
Let's say I have a simple view
<html>
<head>
<title>something</title>
</head>
<body>
<%= param %>
</body>
<script type="text/javascript" src="myscript.js"></script>
</html>
And here myscript.js
$(function() {
var p = <%= param %>
}
Can I make the express rendering engine (in this case ejs
) internally myscript.js
?
0
source to share
1 answer
I don't believe express will touch your static files. You can make this view to be displayed and served from the route, for example:
app.get('/js/myscript.js', function(req, res) {
res.render('myscript');
});
With regular expressions, you can do this with anything ending in .js
. Note that he could and should not .)
You will probably be better off with static javascript to be served in a browser that uses the JSON data served by Express.
+2
source to share