How to use the os.userInfo function in os

To help you get started, we’ve selected a few os examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hufuman / wxbot / example / hot-reload / index.js View on Github external
const os = require('os');
const fs = require('fs');
const path = require('path');
const WeChatBot = require('../../wechat');

const reload = require('require-reload')(require);

// init weChatBot
let options = {
	basePath: path.join(os.userInfo().homedir, 'Desktop')
}
let weChatBot = new WeChatBot(options);

// hot-reload bot.js
let Bot = reload('./bot');
let bot = new Bot(weChatBot);
let reloading = false;
fs.watch('./bot.js', () => {
	if(reloading)
		return;
	reloading = true;
	setTimeout(() => {
		try {
			Bot = reload('./bot');
			bot = new Bot(weChatBot);
			console.log('bot reloaded');
github jamaljsr / polar / src / lib / docker / dockerService.ts View on Github external
private getArgs(network?: Network) {
    const args = {
      cwd: network ? network.path : __dirname,
      env: {
        ...process.env,
        ...(remote && remote.process ? remote.process.env : {}),
      },
    };

    if (isLinux()) {
      const { uid, gid } = os.userInfo();
      debug(`env: uid=${uid} gid=${gid}`);
      args.env = {
        ...args.env,
        // add user/group id's to env so that file permissions on the
        // docker volumes are set correctly. containers cannot write
        // to disk on linux if permissions aren't set correctly
        USERID: uid,
        GROUPID: gid,
      };
    }

    return args;
  }
github oznu / homebridge-config-ui-x / src / pm.ts View on Github external
executeCommand(command, cwd) {
    let timeoutTimer;
    command = command.filter(x => x.length);

    // sudo mode is requested in plugin config
    if (hb.useSudo) {
      command.unshift('sudo', '-E', '-n');
    }

    hb.log(`Running Command: ${command.join(' ')}`);
    this.wssBroadcast(color.cyan(`USER: ${os.userInfo().username}\n\r`));
    this.wssBroadcast(color.cyan(`DIR: ${cwd}\n\r`));
    this.wssBroadcast(color.cyan(`CMD: ${command.join(' ')}\n\r\n\r`));

    return new Bluebird((resolve, reject) => {
      const term = pty.spawn(command.shift(), command, {
        name: 'xterm-color',
        cols: 80,
        rows: 30,
        cwd: cwd,
        env: process.env
      });

      // send stdout data from the process to all clients
      term.on('data', (data) => {
        this.wssBroadcast(data);
      });
github aws / aws-cdk / packages / aws-cdk / lib / version.ts View on Github external
public static timestampFilePath(): string {
    // Get the home directory from the OS, first. Fallback to $HOME.
    const homedir = os.userInfo().homedir || os.homedir();
    if (!homedir || !homedir.trim()) {
      throw new Error('Cannot determine home directory');
    }
    // Using the same path from account-cache.ts
    return path.join(homedir, '.cdk', 'cache', 'repo-version-ttl');
  }
github OfficeDev / Office-Add-in-NodeJS-SSO / SSOAutoSetup / src / configure / ssoAppDataSetttings.js View on Github external
function addSecretToCredentialStore(ssoAppName, secret) {
    try {
        switch (process.platform) {
            case "win32":
                console.log(`Adding application secret for ${ssoAppName} to Windows Credential Store`);
                const addSecretToWindowsStoreCommand = `powershell -ExecutionPolicy Bypass -File "${defaults.addSecretCommandPath}" "${ssoAppName}" "${os.userInfo().username}" "${secret}"`;
                childProcess.execSync(addSecretToWindowsStoreCommand, { stdio: "pipe" });
                break;
            case "darwin":
                console.log(`Adding application secret for ${ssoAppName} to Mac OS Keychain`);
                const addSecretToMacStoreCommand = `sudo security add-generic-password -a ${os.userInfo().username} -s "${ssoAppName}" -w "${secret}"`;
                childProcess.execSync(addSecretToMacStoreCommand, { stdio: "pipe" });
                break;
            default:
                throw new Error(`Platform not supported: ${process.platform}`);
        }
    } catch (err) {
        throw new Error(`Unable to add secret for ${ssoAppName} to Windows Credential Store. \n${err}`);
    }
}
github chrisknepper / android-messages-desktop / src / helpers / utilities.js View on Github external
function isDictionariesFolderOwnedByUser() {
    const stat = statSync(SPELLING_DICTIONARIES_PATH);
    const mUserInfo = userInfo();
    return isObject(stat) && isObject(mUserInfo) && 'uid' in stat && 'uid' in mUserInfo && stat.uid === mUserInfo.uid;
}
github loggin-js / loggin-js / src / lib / logger.js View on Github external
if (typeof name !== 'string') {
      throw new Error('"name" must be a string got: ' + typeof name);
    }
    if (typeof notifierName !== 'string') {
      throw new Error('"notifierName" must be a string got: ' + typeof notifierName);
    }

    Logger[name] = Logger._loggers[name] = notifierName;

    return Logger;
  }
}

Logger._loggers = {};
Logger.DefaultOptions = {
  user: os.userInfo ? os.userInfo().username : 'browser',
  ignore: null,
  preNotify: null,
  level: Severity.DEBUG,
  channel: path.basename(__filename),
  formatter: Formatter.get('detailed'),
  enabled: true,
  color: false,
};

module.exports = Logger;
github tobiastimm / code-theme-converter / lib / util.js View on Github external
function getUsername() {
  return os.userInfo().username
}
github RiseVision / rise-node / packages / cli / src / shared / misc.ts View on Github external
export function getUsername(): string {
  return os.userInfo().username;
}