I am creating a small application with a JavaScript client (run in the browser) and a Node.js server, communicating using WebSocket.(我正在使用JavaScript客户端(在浏览器中运行)和Node.js服务器创建一个小应用程序,使用WebSocket进行通信。)
I would like to share code between the client and the server.(我想在客户端和服务器之间共享代码。)
I have only just started with Node.js and my knowledge of modern JavaScript is a little rusty, to say the least.(我刚刚开始使用Node.js,至少可以说,我对现代JavaScript的了解有点生疏。) So I am still getting my head around the CommonJS require() function.(所以我仍然围绕CommonJS的require()函数。) If I am creating my packages by using the 'export' object, then I cannot see how I could use the same JavaScript files in the browser.(如果我使用'export'对象创建我的包,那么我无法看到如何在浏览器中使用相同的JavaScript文件。)
I want to create a set of methods and classes that are used on both ends to facilitate encoding and decoding messages, and other mirrored tasks.(我想创建一组在两端使用的方法和类,以便于编码和解码消息,以及其他镜像任务。)
However, the Node.js/CommonJS packaging systems seems to preclude me from creating JavaScript files that can be used on both sides.(但是,Node.js / CommonJS打包系统似乎阻止我创建可以在双方使用的JavaScript文件。)
I also tried using JS.Class to get a tighter OO model, but I gave up because I couldn't figure out how to get the provided JavaScript files to work with require().(我也尝试使用JS.Class来获得更紧密的OO模型,但我放弃了,因为我无法弄清楚如何让提供的JavaScript文件与require()一起使用。)
Is there something am I missing here?(这里有什么我想念的吗?)
ask by Simon Cave translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…