In Node.js, how do I “include” functions from my other files?

后端 未结 25 2556
猫巷女王i
猫巷女王i 2020-11-22 04:22

Let\'s say I have a file called app.js. Pretty simple:

var express = require(\'express\');
var app = express.createServer();
app.set(\'views\', __dirname + \         


        
相关标签:
25条回答
  • 2020-11-22 05:09

    You can put your functions in global variables, but it's better practice to just turn your tools script into a module. It's really not too hard – just attach your public API to the exports object. Take a look at Understanding Node.js' exports module for some more detail.

    0 讨论(0)
提交回复
热议问题