1. 程式人生 > 其它 >npm和node.js簡介

npm和node.js簡介

JavaScript和C都是程式語言。執行庫和語言是兩碼事,如C的fopen和fprintf; JS在瀏覽器裡執行的時候,可以呼叫alert()和console.log().

C是編譯型語言,編譯成.exe後單獨執行;JS則需要個直譯器/虛擬機器(Virtual Machine)/引擎。

微軟有自己的引擎,把下面的程式碼輸入進t.js:

var WSHShell = WScript.CreateObject("WScript.Shell");
WSHShell.Popup("Hello World")

在資源管理器裡雙擊t.sj即可彈出對話方塊。

Node.js is a JavaScriptruntime environment. It's built on Google's Chrome's V8 JavaScript engine.Itexecutes JavaScript code outside of a browser. 瀏覽器都自帶JS引擎。

npm是Node.js的包管理工具,通過它可以下載和升級包。包=1個或多個.js檔案。

我頭一次看到npm install -g npm 時,內心是崩潰的。我就是不知道到哪裡去下載npm啊!我倒是知道要先裝python,裝完有了pip,然後pip可以升級pip.

Node.js (nodejs.org)首頁有下載連結,還會根據你用的作業系統做推薦。莫怕,瀏覽器連線Web server時會發送個User agent: xxx 字串,裡面有且僅有作業系統的名字和版本,沒有你的名字和密碼。你是user,瀏覽器是你的代理(agent).

在Windows下,當你輸入npm或npx(Node package runner)時,執行的是npm.cmd或npx.cmd. .cmd是個文字檔案,是.bat的現代版,最終執行node.exe. 所以如果你沒有把D:\npm加入路徑,而是D:\work\t>d:\npm\npm,就會遇到node.exe找不到的錯誤。Linux下npm是個bash 指令碼。

node.exe 52,957KB,我帶有偏見地認為惡大。ffmpeg.exe112MB,人功能強大啊。不過git佔了728MB, 光git*.exe就有139個,468MB,好吧,node.js小而美。可不如tdm-gcc-10.3.0.exe 62MB美,C和C++編譯器,linker, gdb...

npm stands for Node Package Manager and it is the default package manager for Node.js. npx stands for Node Package Execute and it comes with the npm, when you installed npm above 5.2.0 version then automatically npx will installed. It is an npm package runner that can execute any package that you want from the npm registry without even installing that package. 雲執行不成?運營商會認為我沒下載這個包,沒跑流量?

Windows下可不是隻能執行.exe檔案:Windows Script Host Examples (All) (robvanderwoude.com)起碼還有vbs和hta. HTML檔案裡可以嵌VBScript。

#!/bin/bash
# a shebang is a term for the "#!" characters that must begin the first line of a script. In musical notation, 
# a "#" is called a sharp and an exclamation point "!" is sometimes referred to as a bang. Thus, shebang
# becomes a shortening of sharp-bang # shebang也是個單詞: the whole thing