win10下使用nodejs安裝及webstorm創建express項目的指導

来源:http://www.cnblogs.com/shugen/archive/2017/05/21/6885566.html
-Advertisement-
Play Games

本文介紹了windows系統下安裝`nvm nodejs`版本管理包。並且配置了阿裡巴巴的`nodejs`的鏡像和`npm`鏡像。並且,結合webstorm創建出了`nodejs express`項目,成功安裝依賴並運行起來。 ...



title: win10下使用nodejs安裝

win10下使用nodejs安裝及webstorm創建express項目的指導

windows下nvm的安裝

熟悉linux下nodejs開發的朋友應該都知道nvm是一款node版本管理的工具,使用nvm我們可以安裝任意多的nodejs版本,以及決定自己的何時使用某個版本。

但是nvm官方在github上托管的nvm倉庫上明確的說明瞭nvm不支持windows系統,但是其給出了兩個不是由他們參與開發的第三方的解決方案。這兩個方案如下:

我自己使用的是nvm-windows,安裝的過程很簡單,首先是需要卸載自己已經安裝過的nodejs和刪除C:\Users<user>\AppData\Roaming\npmnpm安裝的全局依賴。

註意
雖然nodejswindows安裝程式提供了nodejs卸載的功能,但是通過其卸載程式卸載了nodejs之後,其安裝文件夾下還會存在部分文件,因此在卸載之後,最好手動刪除其安裝目錄。

nvm的安裝比較簡單,因此,在這裡就不再放圖了,有問題的話,可以參考nvm-windows官網

使用NVM安裝nodejs

因為nvm只是一個nodejs的環境管理包,因此,我們在成功的安裝了nvm之後,我們要手動安裝我們需要的nodejs版本。
根據nvm-windows提供的常用的命令如下:

  • nvm arch [32|64]:該命令用來查看當前的nodejs是運行在32位/64位windows系統之上。也可以指定相應的位數來覆蓋預設的設置。

    # 查看當前的nodejs架構
    $ nvm arch
    System Default: 64-bit.
    Currently Configured: 64-bit.

enter description here

  • nvm install

Downloading npm version 3.10.10... Complete
Installing npm v3.10.10...
Installation complete. If you want to use this version, type
nvm use 6.10.2
```

enter description here

註意
如果你第一次使用nvm install 版本號來安裝nodejs,需要使用下麵的nvm use來選擇你的nodejs環境,use後才能使用npm等操作。

  • nvm list [available]:查看當前系統中安裝了哪些版本的nodejs
    ```javascript?linenums
    $ nvm list
  • 6.10.3 (Currently using 64-bit executable)
    6.10.2
    ```

enter description here

  • nvm use

$ nvm use 6.10.3
Now using node v6.10.3 (64-bit)
```

enter description here

  • nvm uninstall

    $ nvm uninstall 6.10.2
    Uninstalling node v6.10.2...Error removing node v6.10.2
    Manually remove C:\Users\Administrator\AppData\Roaming\nvm\v6.10.2.

enter description here

  • nvm root

enter description here

Administrator@neil-PC MINGW64 /c/Program Files
$ ls -n | grep nodejs
lrwxrwxrwx 1 197108 197121  50 5月  21 17:27 nodejs -> /c/Users/Administrator/AppData/Roaming/nvm/v6.10.3/

enter description here
我在自己電腦上使用的是預設的配置,可以看到我的nodejs實際的存放路徑是:

$ nvm root
Current Root: C:\Users\Administrator\AppData\Roaming\nvm

enter description here

  • nvm node_mirror

enter description here

  • nvm npm_mirror

$ npm install -g jslint
C:\Program Files\nodejs\jslint -> C:\Program Files\nodejs\node_modules\jslint\bin\jslint.js
C:\Program Files\nodejs
-- [email protected] +-- [email protected] +-- [email protected] | +-- [email protected] | +-- [email protected] | |-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | -- [email protected] | | +-- [email protected] | |-- [email protected]
| +-- [email protected]
| -- [email protected] +-- [email protected] |-- [email protected]
-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected]-- [email protected]


![enter description here][14]

如果想切換回官方的`npm`鏡像地址,可以使用`nvm npm_mirror http://r.cnpmjs.org/`切換回來。

Administrator@neil-PC MINGW64 ~/WebstormProjects
$ nvm npm_mirror http://r.cnpmjs.org/

Administrator@neil-PC MINGW64 ~/WebstormProjects
$ npm install -g create-react-app
C:\Program Files\nodejs\create-react-app -> C:\Program Files\nodejs\node_modules\create-react-app\index.js
C:\Program Files\nodejs
-- [email protected] +-- [email protected] | +-- [email protected] | +-- [email protected] | +-- [email protected] | |-- [email protected]
| +-- [email protected]
| -- [email protected] +-- [email protected] |-- [email protected]
+-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | -- [email protected] |-- [email protected]
| -- [email protected] +-- [email protected] | +-- [email protected] | +-- [email protected] |-- [email protected]
+-- [email protected]
| +-- [email protected]
| | -- [email protected] | | +-- [email protected] | | |-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | -- [email protected] | |-- [email protected]
| | +-- [email protected]
| | -- [email protected] | +-- [email protected] | |-- [email protected]
| | +-- [email protected]
| | -- [email protected] |-- [email protected]
| +-- [email protected]
| -- [email protected] +-- [email protected] +-- [email protected] | +-- [email protected] | |-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | -- [email protected] | |-- [email protected]
| +-- [email protected]
| | -- [email protected] | |-- [email protected]
| | +-- [email protected]
| | -- [email protected] | +-- [email protected] | |-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | | -- [email protected] | |-- [email protected]
| +-- [email protected]
| | -- [email protected] | | +-- [email protected] | | +-- [email protected] | |-- [email protected]
| +-- [email protected]
| | -- [email protected] |-- [email protected]
+-- [email protected]
| -- [email protected]-- [email protected]
`-- [email protected]


![enter description here][15]

## 使用`webstorm`來創建`express`應用

前面一章說過,`nvm`安裝`nodejs`的方式是在`nvm root`指定的地址中存放實際的`nodejs`應用程式,只是在`C:\Program Files`下創建了一個軟連接而已。而`webstorm`比較坑的就是,不會認出那是一個軟連接,因此,我們需要用命令`nvm root`或者`C:\Program Files\nodejs`的屬性來查看當前的`nodejs`的實際地址。
我當前的`nodejs`的實際地址是`~/AppData/Roaming/nvm/v6.10.3/`。

![enter description here][16]

下麵創建步驟直接上圖和對圖進行說明,相似讀者能夠看明白。

在進行創建項目時,我們需要安裝`express-generator`(我的電腦上已經安裝過了)

$ npm install express-generator -g
C:\Program Files\nodejs\express -> C:\Program Files\nodejs\node_modules\express-generator\bin\express-cli.js
C:\Program Files\nodejs
`-- [email protected]
```

enter description here

enter description here

從上圖可以看出webstorm識別出了C:\Program Files\nodejs作為nodejs的路徑,但是它給出一個提示Unspecified express-generator package version,這顯然是不合理的。

而造成這種現象的原因就是C:\Program Files\nodejs是指一個軟連接,因此C:\Program Files\nodejs下的npmpackage是不能被web-storm正確的識別出來的。因此,我們需要手動配置一下nodejs的實際路徑。

enter description here

enter description here

enter description here

enter description here

選擇~/AppData/Roaming/nvm/v6.10.3/node.exe作為nodejs攔截器之後,webstorm已經正確的識別出來我們當前安裝的express-generator了。我們選擇自己喜歡的html模板和CSS預編譯方式之後,輸入正確的工程名,就可以創建express項目了。

enter description here

創建好的工程截圖如下:
enter description here

enter description here

enter description here

總結

本文介紹了windows系統下安裝nvm nodejs版本管理包。並且配置了阿裡巴巴的nodejs的鏡像和npm鏡像。並且,結合webstorm創建出了nodejs express項目,成功安裝依賴並運行起來。


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 一、為什麼要使用Python進行數據分析? python擁有一個巨大的活躍的科學計算社區,擁有不斷改良的庫,能夠輕鬆的集成C,C++,Fortran代碼(Cython項目),可以同時用於研究和原型的構建以及生產系統的構建。 二、Python的優勢與劣勢: 1.Python是一種解釋型語言,運行速度比 ...
  • 線性回歸、對數幾率回歸模型,本質上是單個神經元。計算輸入特征加權和。偏置視為每個樣本輸入特征為1權重,計算特征線性組合。激活(傳遞)函數 計算輸出。線性回歸,恆等式(值不變)。對數幾率回歸,sigmoid。輸入->權重->求和->傳遞->輸出。softmax分類含C個神經元,每個神經元對應一個輸出類 ...
  • CV_EXPORTS_W void approxPolyDP( InputArray curve, OutputArray approxCurve, double epsilon, bool closed ); @param curve Input vector of a 2D point stor ...
  • 設計模式零 一、設計模式分類 創建型:創建對象的模式 結構型:討論類和對象的結構 行為型:關註對象的行為,解決對象之間的聯繫問題。 二、設計原則 2.1 單一職責原則 只有一個引起它變化的原因,一個類只有一個職責。 2.2 里氏替換原則 父類能出現的地方能用子類替換,但是反過來不一定可以。 2.3 ...
  • 上節談了談類工廠/對象查找服務,本節談談AOP的實現。 AOP為Aspect Oriented Programming的縮寫,意為:面向切麵編程,通過預編譯方式和運行期動態代理實現程式功能的統一維護的一種技術。 Netop.Core的AOP採用代理的實現方式。採用代理方式,您的類就必須繼承一個基類( ...
  • 截止目前,筆者在博客園上面已經發表了3篇關於網路下載的文章,這三篇博客實現了基於socket的http多線程遠程斷點下載實用程式。筆者打算在此基礎上開發出一款分散式文件管理實用程式,截止目前,已經實現了 服務端/客戶端 的上傳、下載部分的功能邏輯。涉及到的知識點包括線程池技術、linux epoll... ...
  • 組合模式:將對象組合成樹形結構以表示“部分-整體”的層次結構。 組合模式使得用戶對單個對象和組合對象的使用具有一致性。 是一種結構型模式 使用場景: 1、用於對象的部分-整體層次結構,如樹形菜單、文件夾菜單、部門組織架構圖等; 2、對用戶隱藏組合對象與單個對象的不同,使得用戶統一地使用組合結構中的所 ...
  • 原文參考http://mp.weixin.qq.com/s?__biz=MzU3MDA0NTMzMA==&mid=2247485490&amp;idx=1&amp;sn=15197b4b53e0669e4a017e54a31fb39c&source=41#wechat_redirect 使用原生js ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...