including js files with html and node.js

前端 未结 2 1834
清歌不尽
清歌不尽 2021-02-14 07:30

I am performing messaging via websockets between a HTML5 client and server running on node.js. Naturally I chose JSON as the message format and as such created common javascript

2条回答
  •  孤街浪徒
    2021-02-14 08:06

    Take a look at nodeJS modules.

    Would be in comm.js:

    module.exports = function(/* any dependency? */){
       // things
       // you can return some object
    }
    

    In the files you need comm.js

    require('./common/js/comm.js')();
    // or you can assign it to a variable if it returned something
    

    Hope that helps!

提交回复
热议问题