官术网_书友最值得收藏!

Installing Node.js

The Node.js installer can be easily obtained by visiting the official Node website and accessing the downloads section. Once there, be sure to download the correct version depending on your OS and CPU (32 bit or 64 bit). As an alternative, you can also use OS-specific package managers to install this. Depending on the OS you are using, just jump into the specific subsection below to get more details on the steps to be followed.

Note

You can jump into the Node.js download sections by following the link http://nodejs.org/download.

Mac OS X

There is a universal installer available from the Node website specifically for OS X.

We need to follow these steps to install Node.js on a Mac:

  1. Visit the download page of the Node.js official website as mentioned earlier and click on the Mac OS X installer, which is independent of the processor type (32 or 64 bit).
  2. Once the download is complete, double-click on the .pkg file, which will launch the Node installer.
  3. Proceed through each step of the wizard that should be fairly self-explanatory.
Mac OS X

Tip

Also, note that if you have any of the OS X package managers installed, then you don't need to manually download the installer. You may install Node.js via the respective package manager.

You may install Node.js via the respective package manager:

  • Installation using Homebrew
    brew install node
    
  • Installation using Mac ports
    port install nodejs
    

    Note

    The installation of Node.js via either an installer or via the package managers will include npm alongside. So, we don't need to install it separately.

Windows

To install Node.js on Windows, we will follow these steps:

  1. We need to determine your processor type, 32 or 64 bit. You can do this by executing the following command at the command prompt:
    $ wmic os get osarchitecture
    

    The output is as follows:

    OSArchiecture
    64-bit
    
  2. Download the installer depending on the result of this command.
  3. Once the download is complete, double-click on the .msi file, which will launch the Node installer.
  4. Proceed through each step of the wizard.
  5. When you get to the custom setup screen, you should notice that the installation wizard will install not only the Node.js runtime, but also the npm package manager, and configure a PATH variable.
  6. So once the installation is done, Node and npm can be executed from any folder via the command line.
    Windows

Also, if you have any of the Windows package managers installed, then you don't need to manually download the installer. You may install Node.js via the respective package manager:

  • Using chocolatey
    cinst nodejs.install
    
  • Using scoop
    scoop install nodejs
    

Linux

Because there are so many different flavors and distributions of Linux available, installing Node isn't quite as straightforward. However, if you're running Linux to begin with, then you are more than aware of this and probably comfortable with a few extra steps.

Joyent has an excellent wiki on how to install Node on Linux using the many different package manager options available. This covers almost all the popular deb and rpm based package managers. You can read that wiki by visiting:

https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

For Ubuntu 12.04 and above as an example, the steps to install Node would be as follows:

$ sudo apt-get update
$ sudo apt-get install python-software-properties python g++ make
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs nodejs-dev npm

Once these steps have been completed, both Node and npm should be installed on your system.

Testing whether Node.js is installed properly

Now that Node has been installed on your system, let's run a quick test to ensure everything is working properly.

Access a command line via your terminal program and execute the following command:

$ node --version
v0.10.35
$ npm --version
2.1.14

Assuming that your Node installation was successful, you should see the version number that was installed as an output on the screen right below the command you executed.

Note

Note that your version numbers will most likely be more recent than those printed earlier.

You can also launch the Node repl, a command-line shell that lets you execute JavaScript directly:

$ node
> console.log('Hello world!')
Hello World!
Undefined
[press Ctrl-C twice to exit]

Online documentation

You'll want to be sure to point your browser to the online documentation for Node and bookmark it, as it will undoubtedly become a resource that you will want to access on a regular basis. It is not mandatory that you should go through each and every section of it, but once you start writing code in Node.js, you will need to refer to this document frequently to understand more on the apis exposed by Node.js. The document is available at: http://nodejs.org/api/.

Also, check out the npm registry available at http://npmjs.com where you can find tens of thousands of modules available for Node developers.

主站蜘蛛池模板: 绿春县| 犍为县| 溧阳市| 金华市| 兴和县| 衡南县| 玉门市| 泰来县| 灵宝市| 新巴尔虎右旗| 昂仁县| 德清县| 呈贡县| 长子县| 安徽省| 精河县| 临猗县| 交口县| 西乌珠穆沁旗| 青阳县| 安化县| 修水县| 会东县| 永年县| 于田县| 垫江县| 潮州市| 会东县| 张掖市| 永善县| 嘉禾县| 商都县| 保山市| 哈尔滨市| 渑池县| 赤壁市| 海宁市| 通榆县| 嘉峪关市| 六安市| 宜川县|