1. 程式人生 > 實用技巧 >素性測試Miller Rabin判質數

素性測試Miller Rabin判質數

npm常用命令

cmd

1.c:
如果我們想訪問c盤,那麼我們需要在命令列中輸入c:就行了

2.cd..
cd..就可以返回上層目錄

3.cd mm
cd mm即可訪問mm資料夾

4.dir
如果想檢視該資料夾下有哪些檔案,則可以在游標處輸入 "dir" 命令

5.連續按兩次Ctrl+C或者輸入“.exit”
在cmd中:
1、輸入node回車即可進入Node.js執行環境。
2、退出只需要連續按兩次Ctrl+C或者輸入“.exit”回車即可。

6.建立資料夾我們可以使用 md <folderName>或mkdir <folderName>命令來建立,
其中md和mkdir都是建立新目錄make directory的意思,
完整命令是md [碟符:\][路徑\]新目錄名,比如:md c:\test\myfolder

7.刪除資料夾呢,使用rd或rmdir命令,完整命令rd /s /q [碟符:\][路徑\]新目錄名,
因為rd只能刪除空的資料夾,
而如果其中有子檔案或子資料夾的時候就會停下來,這時我們加上/s就可以直接刪除,
但是刪除過程中會提示你是否確定刪除,
對於懶癌患者我們有添加了/q,即quiet,安靜模式;
所以使用以上命令會完整刪除你選中的整個資料夾。

8.首先是建立空檔案,命令type nul>*.*;
type nul>myfile.txt
type nul>.test

建立非空檔案,命令echo [fileContent]>*.*,
如echo myname>a.txt

刪除檔案,命令del *.*,如del myfile.txt


9.重新命名資料夾
rename 加需要被你重新命名的資料夾路徑和資料夾原名。例如:
rename d:\system\新建資料夾 電影

10.清屏 全部清理掉了。
跟我來,輸入cls

11.批量順序執行cmd命令

cd/dF:\2\2

1.bat cd/dF:\2\31 1.bat

node

1.我們可以使用以下命令來檢視當前的 Node 版本:
$ node -v
v4.4.3
2.
指令碼模式
以下是我們的第一個Node.js程式:
例項
console.log("Hello World");

執行例項 »
儲存該檔案,檔名為 helloworld.js, 並通過 node命令來執行:
node helloworld.js
程式執行後,正常的話,就會在終端輸出 Hello World。

互動模式
開啟終端,鍵入node進入命令互動模式,可以輸入一條程式碼語句後立即執行並顯示結果,例如:
$ node
> console.log('Hello World!');
Hello World!

3.建立 Node.js 應用
步驟一、引入 required 模組
我們使用 require 指令來載入 http 模組,並將例項化的 HTTP 賦值給變數 http,例項如下:
var http = require("http");
步驟二、建立伺服器
接下來我們使用 http.createServer() 方法建立伺服器,並使用 listen 方法繫結 8888 埠。 函式通過 request, response 引數來接收和響應資料。
例項如下,在你專案的根目錄下建立一個叫 server.js 的檔案,並寫入以下程式碼:
var http = require('http');

http.createServer(function (request, response) {

// 傳送 HTTP 頭部
// HTTP 狀態值: 200 : OK
// 內容型別: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// 傳送響應資料 "Hello World"
response.end('Hello World\n');
}).listen(8888);

// 終端列印如下資訊
console.log('Server running at http://127.0.0.1:8888/');
以上程式碼我們完成了一個可以工作的 HTTP 伺服器。
使用 node 命令執行以上的程式碼:
node server.js
Server running at http://127.0.0.1:8888/

接下來,開啟瀏覽器訪問 http://127.0.0.1:8888/,你會看到一個寫著 "Hello World"的網頁。
分析Node.js 的 HTTP 伺服器:
第一行請求(require)Node.js 自帶的 http 模組,並且把它賦值給 http 變數。
接下來我們呼叫 http 模組提供的函式: createServer 。這個函式會返回 一個物件,這個物件有一個叫做 listen 的方法,這個方法有一個數值引數, 指定這個 HTTP 伺服器監聽的埠號。

4.
1.我們可以輸入以下命令來啟動 Node 的終端:
$ node
>

Node.js REPL(Read Eval Print Loop:互動式直譯器) 表示一個電腦的環境,類似 Window 系統的終端或 Unix/Linux shell,我們可以在終端中輸入命令,並接收系統的響應。
Node 自帶了互動式直譯器,可以執行以下任務:
讀取 - 讀取使用者輸入,解析輸入了Javascript 資料結構並存儲在記憶體中。
執行 - 執行輸入的資料結構
列印 - 輸出結果
迴圈 - 迴圈操作以上步驟直到使用者兩次按下 ctrl-c 按鈕退出。
Node 的互動式直譯器可以很好的除錯 Javascript 程式碼。
開始學習 REPL
我們可以輸入以下命令來啟動 Node 的終端:
$ node
>
這時我們就可以在 > 後輸入簡單的表示式,並按下回車鍵來計算結果。
簡單的表示式運算
接下來讓我們在 Node.js REPL 的命令列視窗中執行簡單的數學運算:
$ node
> 1 +4
5
> 5 / 2
2.5
> 3 * 6
18
> 4 - 1
3
> 1 + ( 2 * 3 ) - 4
3
>
使用變數
你可以將資料儲存在變數中,並在你需要的時候使用它。
變數宣告需要使用 var 關鍵字,如果沒有使用 var 關鍵字變數會直接打印出來。
使用 var 關鍵字的變數可以使用 console.log() 來輸出變數。
$ node
> x = 10
10
> var y = 10
undefined
> x + y
20
> console.log("Hello World")
Hello World
undefined
> console.log("www.runoob.com")
www.runoob.com
undefined
多行表示式
Node REPL 支援輸入多行表示式,這就有點類似 JavaScript。接下來讓我們來執行一個 do-while 迴圈:
$ node
> var x = 0
undefined
> do {
... x++;
... console.log("x: " + x);
... } while ( x < 5 );
x: 1
x: 2
x: 3
x: 4
x: 5
undefined
>
... 三個點的符號是系統自動生成的,你回車換行後即可。Node 會自動檢測是否為連續的表示式。
下劃線(_)變數
你可以使用下劃線(_)獲取表示式的運算結果:
$ node
> var x = 10
undefined
> var y = 20
undefined
> x + y
30
> var sum = _
undefined
> console.log(sum)
30
undefined
>
REPL 命令
ctrl + c - 退出當前終端。
ctrl + c 按下兩次 - 退出 Node REPL。
ctrl + d - 退出 Node REPL.
向上/向下 鍵 - 檢視輸入的歷史命令
tab 鍵 - 列出當前命令
.help - 列出使用命令
.break - 退出多行表示式
.clear - 退出多行表示式
.save filename - 儲存當前的 Node REPL 會話到指定檔案
.load filename - 載入當前 Node REPL 會話的檔案內容。
停止 REPL
前面我們已經提到按下兩次 ctrl + c 鍵就能退出 REPL:
$ node
>
(^C again to quit)
>

npm

1.npm -v
通過輸入 "npm -v" 來測試是否成功安裝。命令如下,出現版本提示表示安裝成功:
$ npm -v
2.3.0
2.sudo npm install npm -g
如果你安裝的是舊版本的 npm,可以很容易得通過 npm 命令來升級,命令如下:
$ sudo npm install npm -g
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
[email protected] /usr/local/lib/node_modules/npm
如果是 Window 系統使用以下命令即可:
npm install npm -g
使用淘寶映象的命令:
cnpm install npm -g
2.$ npm install <Module Name>
npm 安裝 Node.js 模組語法格式如下:
$ npm install <Module Name>
使用 npm 命令安裝常用的 Node.js web框架模組 express:
$ npm install express
安裝好之後,express 包就放在了工程目錄下的 node_modules 目錄中,因此在程式碼中只需要通過 require('express') 的方式就好,無需指定第三方包路徑。
var express = require('express');
npm 的包安裝分為本地安裝(local)、全域性安裝(global)兩種,從敲的命令列來看,差別只是有沒有-g而已,比如
npm install express # 本地安裝
npm install express -g # 全域性安裝
如果出現以下錯誤:
npm err! Error: connect ECONNREFUSED 127.0.0.1:8087
解決辦法為:
$ npm config set proxy null
本地安裝
1. 將安裝包放在 ./node_modules 下(執行 npm 命令時所在的目錄),如果沒有 node_modules 目錄,會在當前執行 npm 命令的目錄下生成 node_modules 目錄。
2. 可以通過 require() 來引入本地安裝的包。
全域性安裝
1. 將安裝包放在 /usr/local 下或者你 node 的安裝目錄。
2. 可以直接在命令列裡使用。
如果你希望具備兩者功能,則需要在兩個地方安裝它或使用 npm link。
接下來我們使用全域性方式安裝 express
$ npm install express -g
安裝過程輸出如下內容,第一行輸出了模組的版本號及安裝位置。
[email protected] node_modules/express
├── [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])
3.$ npm list -g
檢視安裝資訊
你可以使用以下命令來檢視所有全域性安裝的模組:
$ npm list -g

├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
……
如果要檢視某個模組的版本號,可以使用命令如下:
$ npm list grunt

projectName@projectVersion /path/to/project/folder
└── [email protected]

使用 package.json
package.json 位於模組的目錄下,用於定義包的屬性。接下來讓我們來看下 express 包的 package.json 檔案,位於 node_modules/express/package.json 內容:
{
"name": "express",
"description": "Fast, unopinionated, minimalist web framework",
"version": "4.13.3",
"author": {
"name": "TJ Holowaychuk",
"email": "[email protected]"
},
"contributors": [
{
"name": "Aaron Heckmann",
"email": "[email protected]"
},
{
"name": "Ciaran Jessup",
"email": "[email protected]"
},
{
"name": "Douglas Christopher Wilson",
"email": "[email protected]"
},
{
"name": "Guillermo Rauch",
"email": "[email protected]"
},
{
"name": "Jonathan Ong",
"email": "[email protected]"
},
{
"name": "Roman Shtylman",
"email": "[email protected]"
},
{
"name": "Young Jae Sim",
"email": "[email protected]"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/strongloop/express.git"
},
"homepage": "http://expressjs.com/",
"keywords": [
"express",
"framework",
"sinatra",
"web",
"rest",
"restful",
"router",
"app",
"api"
],
"dependencies": {
"accepts": "~1.2.12",
"array-flatten": "1.1.1",
"content-disposition": "0.5.0",
"content-type": "~1.0.1",
"cookie": "0.1.3",
"cookie-signature": "1.0.6",
"debug": "~2.2.0",
"depd": "~1.0.1",
"escape-html": "1.0.2",
"etag": "~1.7.0",
"finalhandler": "0.4.0",
"fresh": "0.3.0",
"merge-descriptors": "1.0.0",
"methods": "~1.1.1",
"on-finished": "~2.3.0",
"parseurl": "~1.3.0",
"path-to-regexp": "0.1.7",
"proxy-addr": "~1.0.8",
"qs": "4.0.0",
"range-parser": "~1.0.2",
"send": "0.13.0",
"serve-static": "~1.10.0",
"type-is": "~1.6.6",
"utils-merge": "1.0.0",
"vary": "~1.0.1"
},
"devDependencies": {
"after": "0.8.1",
"ejs": "2.3.3",
"istanbul": "0.3.17",
"marked": "0.3.5",
"mocha": "2.2.5",
"should": "7.0.2",
"supertest": "1.0.1",
"body-parser": "~1.13.3",
"connect-redis": "~2.4.1",
"cookie-parser": "~1.3.5",
"cookie-session": "~1.2.0",
"express-session": "~1.11.3",
"jade": "~1.11.0",
"method-override": "~2.3.5",
"morgan": "~1.6.1",
"multiparty": "~4.1.2",
"vhost": "~3.0.1"
},
"engines": {
"node": ">= 0.10.0"
},
"files": [
"LICENSE",
"History.md",
"Readme.md",
"index.js",
"lib/"
],
"scripts": {
"test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/",
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/",
"test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/"
},
"gitHead": "ef7ad681b245fba023843ce94f6bcb8e275bbb8e",
"bugs": {
"url": "https://github.com/strongloop/express/issues"
},
"_id": "[email protected]",
"_shasum": "ddb2f1fb4502bf33598d2b032b037960ca6c80a3",
"_from": "express@*",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "[email protected]"
},
"maintainers": [
{
"name": "tjholowaychuk",
"email": "[email protected]"
},
{
"name": "jongleberry",
"email": "[email protected]"
},
{
"name": "dougwilson",
"email": "[email protected]"
},
{
"name": "rfeng",
"email": "[email protected]"
},
{
"name": "aredridel",
"email": "[email protected]"
},
{
"name": "strongloop",
"email": "[email protected]"
},
{
"name": "defunctzombie",
"email": "[email protected]"
}
],
"dist": {
"shasum": "ddb2f1fb4502bf33598d2b032b037960ca6c80a3",
"tarball": "http://registry.npmjs.org/express/-/express-4.13.3.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/express/-/express-4.13.3.tgz",
"readme": "ERROR: No README data found!"
}
Package.json 屬性說明
name - 包名。
version - 包的版本號。
description - 包的描述。
homepage - 包的官網 url 。
author - 包的作者姓名。
contributors - 包的其他貢獻者姓名。
dependencies - 依賴包列表。如果依賴包沒有安裝,npm 會自動將依賴包安裝在 node_module 目錄下。
repository - 包程式碼存放的地方的型別,可以是 git 或 svn,git 可在 Github 上。
main - main 欄位指定了程式的主入口檔案,require('moduleName') 就會載入這個檔案。這個欄位的預設值是模組根目錄下面的 index.js。
keywords - 關鍵字
解除安裝模組
我們可以使用以下命令來解除安裝 Node.js 模組。
$ npm uninstall express
解除安裝後,你可以到 /node_modules/ 目錄下檢視包是否還存在,或者使用以下命令檢視:
$ npm ls
更新模組
我們可以使用以下命令更新模組:
$ npm update express
搜尋模組
使用以下來搜尋模組:
$ npm search express

建立模組
建立模組,package.json 檔案是必不可少的。我們可以使用 NPM 生成 package.json 檔案,生成的檔案包含了基本的結果。
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (node_modules) runoob # 模組名
version: (1.0.0)
description: Node.js 測試模組(www.runoob.com) # 描述
entry point: (index.js)
test command: make test
git repository: https://github.com/runoob/runoob.git # Github 地址
keywords:
author:
license: (ISC)
About to write to ……/node_modules/package.json: # 生成地址

{
"name": "runoob",
"version": "1.0.0",
"description": "Node.js 測試模組(www.runoob.com)",
……
}


Is this ok? (yes) yes
以上的資訊,你需要根據你自己的情況輸入。在最後輸入 "yes" 後會生成 package.json 檔案。
接下來我們可以使用以下命令在 npm 資源庫中註冊使用者(使用郵箱註冊):
$ npm adduser
Username: mcmohd
Password:
Email: (this IS public) [email protected]
接下來我們就用以下命令來發布模組:
$ npm publish
如果你以上的步驟都操作正確,你就可以跟其他模組一樣使用 npm 來安裝。
版本號
使用NPM下載和釋出程式碼時都會接觸到版本號。NPM使用語義版本號來管理程式碼,這裡簡單介紹一下。
語義版本號分為X.Y.Z三位,分別代表主版本號、次版本號和補丁版本號。當代碼變更時,版本號按以下原則更新。
如果只是修復bug,需要更新Z位。
如果是新增了功能,但是向下相容,需要更新Y位。
如果有大變動,向下不相容,需要更新X位。
版本號有了這個保證後,在申明第三方包依賴時,除了可依賴於一個固定版本號外,還可依賴於某個範圍的版本號。例如"argv": "0.0.x"表示依賴於0.0.x系列的最新版argv。
NPM支援的所有版本號範圍指定方式可以檢視官方文件。

NPM 常用命令
除了本章介紹的部分外,NPM還提供了很多功能,package.json裡也有很多其它有用的欄位。
除了可以在npmjs.org/doc/檢視官方文件外,這裡再介紹一些NPM常用命令。
NPM提供了很多命令,例如install和publish,使用npm help可檢視所有命令。
NPM提供了很多命令,例如install和publish,使用npm help可檢視所有命令。
使用npm help <command>可檢視某條命令的詳細幫助,例如npm help install。
在package.json所在目錄下使用npm install . -g可先在本地安裝當前命令列程式,可用於釋出前的本地測試。
使用npm update <package>可以把當前目錄下node_modules子目錄裡邊的對應模組更新至最新版本。
使用npm update <package> -g可以把全域性安裝的對應命令列程式更新至最新版。
使用npm cache clear可以清空NPM本地快取,用於對付使用相同版本號釋出新版本程式碼的人。
使用npm unpublish <package>@<version>可以撤銷釋出自己釋出過的某個版本程式碼。
使用淘寶 NPM 映象
大家都知道國內直接使用 npm 的官方映象是非常慢的,這裡推薦使用淘寶 NPM 映象。
淘寶 NPM 映象是一個完整 npmjs.org 映象,你可以用此代替官方版本(只讀),同步頻率目前為 10分鐘 一次以保證儘量與官方服務同步。
你可以使用淘寶定製的 cnpm (gzip 壓縮支援) 命令列工具代替預設的 npm:
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
這樣就可以使用 cnpm 命令來安裝模組了:
$ cnpm install [name]

原文連結:https://www.cnblogs.com/liuqiyun/p/8026340.html