You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.6 KiB

3 months ago
  1. # arch [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
  2. [travis-image]: https://img.shields.io/travis/feross/arch/master.svg
  3. [travis-url]: https://travis-ci.org/feross/arch
  4. [npm-image]: https://img.shields.io/npm/v/arch.svg
  5. [npm-url]: https://npmjs.org/package/arch
  6. [downloads-image]: https://img.shields.io/npm/dm/arch.svg
  7. [downloads-url]: https://npmjs.org/package/arch
  8. [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
  9. [standard-url]: https://standardjs.com
  10. ### Better `os.arch()` for node and the browser -- detect OS architecture
  11. [![Sauce Test Status](https://saucelabs.com/browser-matrix/arch2.svg)](https://saucelabs.com/u/arch2)
  12. This module is used by [WebTorrent Desktop](http://webtorrent.io/desktop) to
  13. determine if the user is on a 32-bit vs. 64-bit operating system to offer the
  14. right app installer.
  15. In Node.js, the `os.arch()` method (and `process.arch` property) returns a string
  16. identifying the operating system CPU architecture **for which the Node.js binary
  17. was compiled**.
  18. This is not the same as the **operating system CPU architecture**. For example,
  19. you can run Node.js 32-bit on a 64-bit OS. In that situation, `os.arch()` will
  20. return a misleading 'x86' (32-bit) value, instead of 'x64' (64-bit).
  21. Use this package to get the actual operating system CPU architecture.
  22. **BONUS: This package works in the browser too.**
  23. ## install
  24. ```
  25. npm install arch
  26. ```
  27. ## usage
  28. ```js
  29. var arch = require('arch')
  30. console.log(arch()) // always returns 'x64' or 'x86'
  31. ```
  32. In the browser, there is no spec that defines where this information lives, so we
  33. check all known locations including `navigator.userAgent`, `navigator.platform`,
  34. and `navigator.cpuClass` to make a best guess.
  35. If there is no *affirmative indication* that the architecture is 64-bit, then
  36. 32-bit will be assumed. This makes this package perfect for determining what
  37. installer executable to offer to desktop app users. If there is ambiguity, then
  38. the user will get the 32-bit installer, which will work fine even for a user with
  39. a 64-bit OS.
  40. For reference, `x64` means 64-bit and `x86` means 32-bit.
  41. Here is some history behind these naming conventions:
  42. - https://en.wikipedia.org/wiki/X86
  43. - https://en.wikipedia.org/wiki/IA-32
  44. - https://en.wikipedia.org/wiki/X86-64
  45. ## Node.js proposal - `os.sysarch()`
  46. Note: There is
  47. [a proposal](https://github.com/nodejs/node-v0.x-archive/issues/2862#issuecomment-103942051)
  48. to add this functionality to Node.js as `os.sysarch()`.
  49. ## license
  50. MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).