How to use the moleculer.clearRequireCache function in moleculer

To help you get started, we’ve selected a few moleculer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github icebob / kantab / backend / middlewares / EnhancedHotReload.js View on Github external
watchItem.watcher = fs.watch(fName, async (eventType) => {
			const relPath = path.relative(process.cwd(), fName);
			broker.logger.info(chalk.magenta.bold(`The '${relPath}' file is changed. (Event: ${eventType})`));

			// Clear from require cache
			clearRequireCache(fName);
			if (watchItem.others.length > 0) {
				watchItem.others.forEach(f => clearRequireCache(f));
			}

			if (watchItem.brokerRestart) {
				// TODO: it is not working properly. The ServiceBroker doesn't reload the config from the moleculer.config.js
				// file because it is loaded by Moleculer Runner (with merged environment files)
				broker.logger.info(chalk.bgMagenta.white.bold("Action: Stop all file watcher & restart broker..."));
				stopAllFileWatcher(projectFiles);
				// Clear the whole require cache
				require.cache.length = 0;
				broker.restart();

			} else if (watchItem.allServices) {
				// Reload all services
				broker.services.forEach(svc => {
github icebob / kantab / backend / middlewares / EnhancedHotReload.js View on Github external
				watchItem.others.forEach(f => clearRequireCache(f));
			}