I have a function (getLocalSecurity) which gets an argument from command prompt and return boolean, as you see here:
server.ts:
import { getDataService } from './service';
import { getInternalService } from './internal/service';
import { ServiceFactory } from './services/serviceFactory';
import { loggers } from 'winston';
const LOG = loggers.get('server');
const mainApp = getDataService();
const cla = require('command-line-arguments');
const params = cla.getCommandLineArguments();
export function getLocalSecurity(): boolean {
return params.LOCAL_SECURITY;
}
LOG.info('Starting server on port 9090...');
On the other typeScript file I want to use it:
import {getLocalSecurity} from './server';
if (getLocalSecurity()) {
console.log('access denied', getLocalSecurity());
return Promise.resolve({});
}
when I use the following sentence in command prompt, getLocalSecurity is false in console.log but in if condition it is true. What is the problem? How can I fix it?
npm run start --- LOCAL_SECURITY -false
return is not a boolean, it is a string, I don't know why !!!!!!! In if condition we have to use the following:
if (getLocalSecurity() === 'false')....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.