在node.js app的客户端导入JS模块的标准方法是什么?
添加<script src="..."></script>
似乎很糟糕,但我看不出还能做什么。
更新
以下是服务器的代码:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
客户:
<!doctype html>
<html>
<head>
<title>Website</title>
<script src="jquery.js"></script> (doesn't work)
</head>
<body>
</body>
</html>
答案 0 :(得分:0)
在index.js中执行此操作:
var module = require('module');
exports.index = function(req, res) {
res.render('index', { module : module});
//Now your EJS will have the module
}