I want to split my application into parts in order to have something like MVC ... Currently, I realized that exports works and how to communicate between different files. The only thing I canβt understand is how to use constants globally? I currently have something like this:
// start.js const ROOT_DIR = __dirname; const APP_DIR = ROOT_DIR + '/app/'; const MODULES_DIR = '/usr/local/lib/node_modules/'; const APP_PORT = 4935; var server = require(APP_DIR + 'server.js'); server.start(); // server.js exports.start = function() { var express = require(MODULES_DIR + 'express'), app = express(), http = require('http'), server = http.createServer(app), io = require(MODULES_DIR + 'socket.io').listen(server), fs = require('fs'), path = require('path'); server.listen(APP_PORT); app.use(express.static(ROOT_DIR + '/assets')); app.get('/', function (req, res) { res.sendfile(ROOT_DIR + '/views/index.html'); }); }
Is it possible to automatically set these constants to server.js or do I need to pass them as variables?
source share