How to use the platform function from os

Find comprehensive JavaScript os.platform code examples handpicked from public code repositorys.

os.platform is a function that returns the operating system platform as a string.

539
540
541
542
543
544
545
546
547
548
549
550
551
} // async handleBlueZManagedObjects(error, objects)




async function init() {
	// Bounce if bluetooth disabled or wrong platform
	if (config.media.bluetooth.enable === false || os.platform() !== 'linux') return false;


	// systemd dbus libraries
	if (bluetooth.dbus === null) {
		bluetooth.dbus = require('dbus-native');
fork icon23
star icon104
watch icon22

1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
usageTracker.send({
	data,
	os: {
		arch: os.arch(),
		cpus: os.cpus(),
		platform: os.platform(),
		release: os.release(),
		version: os.version()
	}
});
fork icon8
star icon62
watch icon7

How does os.platform work?

os.platform is a function provided by the Node.js os module that returns a string indicating the operating system platform on which the Node.js process is running. The returned string will be one of: 'aix': IBM AIX 'darwin': macOS 'freebsd': FreeBSD 'linux': Linux 'openbsd': OpenBSD 'sunos': Oracle Solaris 'win32': Windows This can be useful for detecting the current platform and writing cross-platform code that behaves differently on different operating systems.

0
1
2
3
4
5
6
7
8
9
10
11
const { BrowserWindow, app, ipcMain, dialog } = require("electron");
const path = require("path");
require("@electron/remote/main").initialize();


const os = require("os");
const platform = os.platform();
const arch = os.arch();


var win;
function createWindow() {
fork icon8
star icon49
watch icon4

257
258
259
260
261
262
263
264
265
266
    'Accept': 'application/json',
    'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
    "Content-Length": data.length,
    'User-Agent': "Chargebee-NodeJs-Client " + env.clientVersion,
    'Lang-Version': process.version,
    'OS-Version': os.platform() + " " + os.arch() + " " + os.release()
});

var req = protocol.request({
    "hostname": getHost(env),
fork icon26
star icon42
watch icon35

Ai Example

1
2
3
4
const os = require("os");

const platform = os.platform();
console.log(`Operating system platform: ${platform}`);

When you run this code, it will print the current operating system platform to the console. For example, on a Linux system, the output might be: perl Copy code

339
340
341
342
343
344
345
346
347
348

let network = require('msb-network');
_client.invoke('notify', id, `Fetching environment state from ${settingsHelper.settings.nodeName}.`, "INFO");

network.get_interfaces_list(function (err, nw) {
    let path = os.platform() === 'win32' ? 'c:' : '/';

    var state = {
        networks: nw,
        memory: {
fork icon4
star icon0
watch icon0

+ 3 other calls in file

6
7
8
9
10
11
12
13
14
15
const Inert = require('@hapi/inert');
const H2o2 = require('@hapi/h2o2');
const bourne = require('@hapi/bourne');
const querystring = require('querystring');
const os = require('os');
const osName = [os.type(), os.platform(), os.release()].join(':');
const hrtime = require('browser-process-hrtime');
const Content = require('@hapi/content');
const Pez = require('@hapi/pez');
const fs = require('fs');
fork icon1
star icon2
watch icon37

+ 2 other calls in file

18
19
20
21
22
23
24
25
26
27
updateWindow = new electron.BrowserWindow({
    title: "Pears Streaming MAJ",
    width: 400,
    height: 500,
    icon: path.join(electron.app.getAppPath(), 'build', 'assets', 'images', 'icon') + `.${os.platform() === "win32" ? "ico" : "png"}`,
    transparent: os.platform() === 'win32',
    frame: false,
    show: false,
    resizable: false,
    webPreferences: {
fork icon0
star icon1
watch icon1

109
110
111
112
113
114
115
116
117
118
119
  const file = Path.join(__dirname, "node_modules/typescript/bin/tsc");
  exec_file("node", [file, "--declaration", "--outDir", target, source]);
}


function ljtc(file, target) {
  const cmd = OS.platform() === "win32" ? "crochet.cmd" : "crochet";
  const result = exec_file_capture(cmd, ["ljtc", "--", "ts", file]);
  FS.writeFileSync(target, result);
}

fork icon0
star icon1
watch icon1

2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
    value: os.hostname()
});

rows.push({
    name: 'Platform',
    value: os.platform()
});

rows.push({
    name: 'CPUs',
fork icon0
star icon1
watch icon1

12
13
14
15
16
17
18
19
20
21
const term = require( 'terminal-kit' ).terminal;
const Downloader = require("nodejs-file-downloader");
const semver = require('semver');
//const _7z = require('7zip-min');
const axios = require('axios')
const platform = os.platform()
const shell = platform === 'win32' ? 'powershell.exe' : 'bash';
const L = require("./llama")
const A = require("./alpaca")
const TorrentDownloader = require("./torrent")
fork icon388
star icon0
watch icon54

525
526
527
528
529
530
531
532
533
534
    // Make sure both dimensions are odd, this is required for vp8
    options.recordVideo.size.width &= ~1;
    options.recordVideo.size.height &= ~1;
  }
  if (options.proxy) {
    if (!browserOptions.proxy && browserOptions.isChromium && os.platform() === 'win32') throw new Error(`Browser needs to be launched with the global proxy. If all contexts override the proxy, global proxy will be never used and can be any string, for example "launch({ proxy: { server: 'http://per-context' } })"`);
    options.proxy = normalizeProxySettings(options.proxy);
  }
  verifyGeolocation(options.geolocation);
}
fork icon0
star icon0
watch icon1

415
416
417
418
419
420
421
422
423
// > 本地文件模式
var info = "";
   if( StorageManager.isLocalMode() ){
	
	var os = require("os");
	info += os.platform();		//操作系统
	info += os.release();		//系统版本
	info += os.type();			//系统名称
	info += os.arch();			//CPU架构
fork icon0
star icon0
watch icon1

772
773
774
775
776
777
778
779
780
781
} else {
    Editor.log(tip);
}

let cmd = '';
// Editor.log('platform:' + os.platform() + ' indexOf(win):' + os.platform().indexOf('win'));
if (os.platform().indexOf('win32') >= 0 || os.platform().indexOf('win64') >= 0) {
    cmd = winNodeCmd;
} else {
    cmd = unixNodeCmd;
fork icon0
star icon0
watch icon1

+ 2 other calls in file

42
43
44
45
46
47
48
49
50
51
}

// install mongodb database tools
// https://www.mongodb.com/docs/database-tools/mongodump/
const pcss = spawn('mongodump', optionArray, {
    shell: os.platform() === "win32" ? true : undefined
});

pcss.on("exit", function(code, signal) {
    if(code) {
fork icon0
star icon0
watch icon1

62
63
64
65
66
67
68
69
70
71
// Track kit start event, with kit version, operating system and Node.js version
const trackingId = 'UA-26179049-21'
const trackingUser = universalAnalytics(trackingId, usageDataConfig.clientId)

const kitVersion = packageJson.version
const operatingSystem = os.platform() + ' ' + os.release()
const nodeVersion = process.versions.node

// Anonymise the IP
trackingUser.set('anonymizeIp', 1)
fork icon0
star icon0
watch icon1

57
58
59
60
61
62
63
64
65
66
};

sentry.configureScope(function(sentryScope) {
  const tags = {
    os_type: os.type(),
    os_platform: os.platform(),
    os_release: os.release(),
    strapi_version: scope.strapiVersion,
    node_version: process.version,
    docker: scope.docker,
fork icon0
star icon0
watch icon1

90
91
92
93
94
95
96
97
98
99
let { age, exp, limit, level, role, registered, money} = global.db.data.users[m.sender]
let { min, xp, max } = levelling.xpRange(level, global.multiplier)
let name = await conn.getName(m.sender)
let premium = global.db.data.users[m.sender].premiumTime
let prems = `${premium > 0 ? 'Premium': 'Free'}`
let platform = os.platform()
let tag = `@${m.sender.split('@')[0]}`
let d = new Date(new Date + 3600000)
let locale = 'id'
// d.getTimeZoneOffset()
fork icon0
star icon0
watch icon0

56
57
58
59
60
61
62
63
64
65
};

sentry.configureScope(function scope(sentryScope) {
  const tags = {
    os: os.type(),
    osPlatform: os.platform(),
    osArch: os.arch(),
    osRelease: os.release(),
    version: scope.strapiVersion,
    nodeVersion: process.versions.node,
fork icon0
star icon0
watch icon1

10
11
12
13
14
15
16
17
18
19
20
const { createNextInstall } = require('./test/lib/create-next-install')
const glob = promisify(_glob)
const exec = promisify(execOrig)


const timings = []
const DEFAULT_NUM_RETRIES = os.platform() === 'win32' ? 2 : 1
const DEFAULT_CONCURRENCY = 2
const RESULTS_EXT = `.results.json`
const isTestJob = !!process.env.NEXT_TEST_JOB
const TIMINGS_API = `https://api.github.com/gists/4500dd89ae2f5d70d9aaceb191f528d1`
fork icon0
star icon0
watch icon1

28
29
30
31
32
33
34
35
36
37
minWidth: 980,
minHeight: 552,
resizable: true,
icon: `./src/assets/images/icon.${os.platform() === "win32" ? "ico" : "png"}`,
transparent: os.platform() === 'win32',
frame: os.platform() !== 'win32',
show: false,
webPreferences: {
    contextIsolation: false,
    nodeIntegration: true
fork icon0
star icon0
watch icon1