test('get username using NSProcessInfo, convert to javascript string and compare the value to the username given by `os.userInfo()`', t => { const NSProcessInfo = objc.NSProcessInfo; const os = require('os'); const processInfo = NSProcessInfo.processInfo(); const username = processInfo.userName(); t.is(String(username), os.userInfo().username); });
// get OS username app.get('/api/getUsername', (req, res) => res.send({ username: os.userInfo().username }));
fs.appendFile('sample.txt', `Welcome ${user.username}. You are ${docs.age} old.`, (err) => { console.log(err); });
$('#send').click(() => { let textarea = $('#textarea').val(); console.log(os.userInfo().username); console.log(textarea); console.log(os.networkInterfaces().en0[1].address); http.get(`http://localhost:${port}/?message=${encodeURIComponent(textarea)}`, (res) => { res.setEncoding('utf8'); let rawData = ''; res.on('data', (chunk) => { rawData += chunk }); res.on('end', () => { console.log(rawData); }) }) });
app.get('/', (req, res) => { switch (req.query.action) { case 'tell': config.channels.forEach(channel => { client.sendMessage( channel, `${require('os').userInfo().username} tells: ${req.query.message}` ); }); res.sendStatus(200); break; default: res.sendStatus(400); break; } });
function getSecretFromCredentialStore(ssoAppName) { try { switch (process.platform) { case "win32": console.log(`Getting application secret for ${ssoAppName} from Windows Credential Store`); const getSecretFromWindowsStoreCommand = `powershell -ExecutionPolicy Bypass -File "${defaults.getSecretCommandPath}" "${ssoAppName}" "${os.userInfo().username}"`; return childProcess.execSync(getSecretFromWindowsStoreCommand, { stdio: "pipe" }).toString(); case "darwin": console.log(`Getting application secret for ${ssoAppName} from Mac OS Keychain`); const getSecretFromMacStoreCommand = `sudo security find-generic-password -a ${os.userInfo().username} -s ${ssoAppName} -w`; return childProcess.execSync(getSecretFromMacStoreCommand, { stdio: "pipe" }).toString();; default: throw new Error(`Platform not supported: ${process.platform}`); } } catch (err) { throw new Error(`Unable to retrieve secret for ${ssoAppName} to Windows Credential Store. \n${err}`); } }
/** * The EACCES fallback is a workaround for npm's `sudo` behavior, where * it drops the permissions before invoking any child processes (like * node-gyp). So what happens is the "nobody" user doesn't have * permission to create the dev dir. As a fallback, make the tmpdir() be * the dev dir for this installation. This is not ideal, but at least * the compilation will succeed... */ function eaccesFallback (err) { var noretry = '--node_gyp_internal_noretry' if (argv.indexOf(noretry) !== -1) { return cb(err) } var tmpdir = os.tmpdir() gyp.devDir = path.resolve(tmpdir, '.node-gyp') var userString = '' try { // os.userInfo can fail on some systems, it's not critical here userString = ` ("${os.userInfo().username}")` } catch (e) {} log.warn('EACCES', 'current user%s does not have permission to access the dev dir "%s"', userString, devDir) log.warn('EACCES', 'attempting to reinstall using temporary dev dir "%s"', gyp.devDir) if (process.cwd() === tmpdir) { log.verbose('tmpdir == cwd', 'automatically will remove dev files after to save disk space') gyp.todo.push({ name: 'remove', args: argv }) } gyp.commands.install([noretry].concat(argv), cb) }
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}`); } }
try { author = os.userInfo() .username; } catch { }
router.get('/api/getUsername', (req, res) => { res.send({username: os.userInfo().username}); })
app.get('/api/getUsername', (req, res) => res.send({ username: os.userInfo().username }));