本文整理匯總了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);