bin/moleculer-runner.js
function loadServices() {
	const fileMask = flags.mask || "**/*.service.js";

	const serviceDir = process.env.SERVICEDIR || "";
	const svcDir = path.isAbsolute(serviceDir) ? serviceDir : path.resolve(process.cwd(), serviceDir);

	let patterns = servicePaths;

	if (process.env.SERVICES || process.env.SERVICEDIR) {

		if (isDirectory(svcDir) && !process.env.SERVICES) {
			// Load all services from directory (from subfolders too)
			broker.loadServices(svcDir, fileMask);

		} else if (process.env.SERVICES) {
			// Load services from env list
			patterns = Array.isArray(process.env.SERVICES) ? process.env.SERVICES : process.env.SERVICES.split(",");
		}
	}

	if (patterns.length > 0) {
		let serviceFiles = [];

		patterns.map(s => s.trim()).forEach(p => {
			const skipping = p[0] == "!";
			if (skipping)
				p = p.slice(1);

			if (p.startsWith("npm:")) {
				// Load NPM module
				loadNpmModule(p.slice(4));

			} else {
				let files;
				const svcPath = path.isAbsolute(p) ? p : path.resolve(svcDir, p);
				// Check is it a directory?
				if (isDirectory(svcPath)) {
					files = glob(svcPath + "/" + fileMask, { absolute: true });
					if (files.length == 0)
						return broker.logger.warn(chalk.yellow.bold(`There is no service files in directory: '${svcPath}'`));
				} else if (isServiceFile(svcPath)) {
					files = [svcPath.replace(/\\/g, "/")];
				} else if (isServiceFile(svcPath + ".service.js")) {
					files = [svcPath.replace(/\\/g, "/") + ".service.js"];
				} else {
					// Load with glob
					files = glob(p, { cwd: svcDir, absolute: true });
					if (files.length == 0)
						broker.logger.warn(chalk.yellow.bold(`There is no matched file for pattern: '${p}'`));
				}

				if (files && files.length > 0) {
					if (skipping)
						serviceFiles = serviceFiles.filter(f => files.indexOf(f) === -1);
					else
						serviceFiles.push(...files);
				}
			}
		});

		_.uniq(serviceFiles).forEach(f => broker.loadService(f));
	}
}
function loadServices() {
	const fileMask = flags.mask || "**/*.service.js";

	const serviceDir = process.env.SERVICEDIR || "";
	const svcDir = path.isAbsolute(serviceDir) ? serviceDir : path.resolve(process.cwd(), serviceDir);

	let patterns = servicePaths;

	if (process.env.SERVICES || process.env.SERVICEDIR) {

		if (isDirectory(svcDir) && !process.env.SERVICES) {
			// Load all services from directory (from subfolders too)
			broker.loadServices(svcDir, fileMask);

		} else if (process.env.SERVICES) {
			// Load services from env list
			patterns = Array.isArray(process.env.SERVICES) ? process.env.SERVICES : process.env.SERVICES.split(",");
		}
	}

	if (patterns.length > 0) {
		let serviceFiles = [];

		patterns.map(s => s.trim()).forEach(p => {
			const skipping = p[0] == "!";
			if (skipping)
				p = p.slice(1);

			if (p.startsWith("npm:")) {
				// Load NPM module
				loadNpmModule(p.slice(4));

			} else {
				let files;
				const svcPath = path.isAbsolute(p) ? p : path.resolve(svcDir, p);
				// Check is it a directory?
				if (isDirectory(svcPath)) {
					files = glob(svcPath + "/" + fileMask, { absolute: true });
					if (files.length == 0)
						return broker.logger.warn(chalk.yellow.bold(`There is no service files in directory: '${svcPath}'`));
				} else if (isServiceFile(svcPath)) {
					files = [svcPath.replace(/\\/g, "/")];
				} else if (isServiceFile(svcPath + ".service.js")) {
					files = [svcPath.replace(/\\/g, "/") + ".service.js"];
				} else {
					// Load with glob
					files = glob(p, { cwd: svcDir, absolute: true });
					if (files.length == 0)
						broker.logger.warn(chalk.yellow.bold(`There is no matched file for pattern: '${p}'`));
				}

				if (files && files.length > 0) {
					if (skipping)
						serviceFiles = serviceFiles.filter(f => files.indexOf(f) === -1);
					else
						serviceFiles.push(...files);
				}
			}
		});

		_.uniq(serviceFiles).forEach(f => broker.loadService(f));
	}
}
function loadServices ( ) { const fileMask = flags . mask || "**/*.service.js" ; const serviceDir = process . env . SERVICEDIR || "" ; const svcDir = path . isAbsolute ( serviceDir ) ? serviceDir : path . resolve ( process . cwd ( ) , serviceDir ) ; let patterns = servicePaths ; if ( process . env . SERVICES || process . env . SERVICEDIR ) { if ( isDirectory ( svcDir ) && ! process . env . SERVICES ) { // Load all services from directory (from subfolders too) broker . loadServices ( svcDir , fileMask ) ; } else if ( process . env . SERVICES ) { // Load services from env list patterns = Array . isArray ( process . env . SERVICES ) ? process . env . SERVICES : process . env . SERVICES . split ( "," ) ; } } if ( patterns . length > 0 ) { let serviceFiles = [ ] ; patterns . map ( s => s . trim ( ) ) . forEach ( p => { const skipping = p [ 0 ] == "!" ; if ( skipping ) p = p . slice ( 1 ) ; if ( p . startsWith ( "npm:" ) ) { // Load NPM module loadNpmModule ( p . slice ( 4 ) ) ; } else { let files ; const svcPath = path . isAbsolute ( p ) ? p : path . resolve ( svcDir , p ) ; // Check is it a directory? if ( isDirectory ( svcPath ) ) { files = glob ( svcPath + "/" + fileMask , { absolute : true } ) ; if ( files . length == 0 ) return broker . logger . warn ( chalk . yellow . bold ( ` ${ svcPath } ` ) ) ; } else if ( isServiceFile ( svcPath ) ) { files = [ svcPath . replace ( / \\ / g , "/" ) ] ; } else if ( isServiceFile ( svcPath + ".service.js" ) ) { files = [ svcPath . replace ( / \\ / g , "/" ) + ".service.js" ] ; } else { // Load with glob files = glob ( p , { cwd : svcDir , absolute : true } ) ; if ( files . length == 0 ) broker . logger . warn ( chalk . yellow . bold ( ` ${ p } ` ) ) ; } if ( files && files . length > 0 ) { if ( skipping ) serviceFiles = serviceFiles . filter ( f => files . indexOf ( f ) === - 1 ) ; else serviceFiles . push ( ... files ) ; } } } ) ; _ . uniq ( serviceFiles ) . forEach ( f => broker . loadService ( f ) ) ; } }
Load services from files or directories

1. If find `SERVICEDIR` env var and not find `SERVICES` env var, load all services from the `SERVICEDIR` directory
2. If find `SERVICEDIR` env var and `SERVICES` env var, load the specified services from the `SERVICEDIR` directory
3. If not find `SERVICEDIR` env var but find `SERVICES` env var, load the specified services from the current directory
4. check the CLI arguments. If it find filename(s), load it/them
5. If find directory(ies), load it/them

Please note: you can use shorthand names for `SERVICES` env var.
E.g.
SERVICES=posts,users

It will be load the `posts.service.js` and `users.service.js` files
Load services from files or directories