本文整理汇总了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;
}
示例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);