当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript portscanner.checkPortStatus函数代码示例

本文整理汇总了TypeScript中portscanner.checkPortStatus函数的典型用法代码示例。如果您正苦于以下问题:TypeScript checkPortStatus函数的具体用法?TypeScript checkPortStatus怎么用?TypeScript checkPortStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了checkPortStatus函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: init

/**
 * Init app
 */
async function init(): Promise<Config> {
	Logger.info('Welcome to Misskey!');

	(new Logger('Deps')).info(`Node.js ${process.version}`);
	MachineInfo.show();
	EnvironmentInfo.show();
	new DependencyInfo().showAll();

	const configLogger = new Logger('Config');
	let config;

	try {
		config = loadConfig();
	} catch (exception) {
		if (typeof exception === 'string') {
			configLogger.error(exception);
			process.exit(1);
		}
		if (exception.code === 'ENOENT') {
			configLogger.error('Configuration file not found');
			process.exit(1);
		}
		throw exception;
	}

	configLogger.succ('Loaded');

	if (process.platform === 'linux' && !isRoot() && config.port < 1024) {
		Logger.error('You need root privileges to listen on port below 1024 on Linux');
		process.exit(1);
	}

	if (await portscanner.checkPortStatus(config.port, '127.0.0.1') === 'open') {
		Logger.error(`Port ${config.port} is already in use`);
		process.exit(1);
	}

	// Try to connect to MongoDB
	checkMongoDb(config);

	return config;
}
开发者ID:ha-dai,项目名称:Misskey,代码行数:45,代码来源:index.ts

示例2: assert

import * as portscanner from 'portscanner';
declare function assert(cond: boolean): void;

const checkPortCallback = (error: Error | null, status: portscanner.Status) => {
    assert(error === null);
    error && assert(error.message === '');
    assert(status === 'open');
    assert(status === 'closed');
};

const assertStatus = (status: portscanner.Status) => {
    assert(status === 'open');
    assert(status === 'closed');
};

portscanner.checkPortStatus(3000).then(assertStatus);

portscanner.checkPortStatus(3000, '127.0.0.1').then(assertStatus);
portscanner.checkPortStatus(3000, { host: '127.0.0.1' }).then(assertStatus);
portscanner.checkPortStatus(3000, { timeout: 400 }).then(assertStatus);
portscanner.checkPortStatus(3000, checkPortCallback);

portscanner.checkPortStatus(3000, { host: '127.0.0.1' }, checkPortCallback);
portscanner.checkPortStatus(3000, { timeout: 400 }, checkPortCallback);
portscanner.checkPortStatus(3000, '127.0.0.1', checkPortCallback);

portscanner.checkPortStatus(3000, '127.0.0.1', { timeout: 400 }).then(assertStatus);
portscanner.checkPortStatus(3000, '127.0.0.1', { timeout: 400 }, checkPortCallback);

const findPortCallback = (error: Error | null, port: number) => {
    assert(error === null);
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:31,代码来源:node-portscanner-tests.ts


注:本文中的portscanner.checkPortStatus函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。