How do I "include" functions from my other files?
@lebyy▲ 0 net votes
Problem: Let's say I have a file called app.js. Pretty simple: var express = require('express'); var app = express.createServer(); app.set('views', __dirname + '/views'); app.set('vie What if I have a functions inside "tools.js". How would I import them to use in… Fix (from the top answer): You can require any js file, you just need to declare what you want to expose. // tools.js // ======== module.exports = { foo: function () { // whatever }, bar: function () { // whatever } }; var zem And in your app file: // app.js // ====== var tools = require('./tools'); console.log(typeof tools.foo); // =>…