分隔線

使用三個連續符號表示(-、*)

1
***

1
---

閱讀全文 »

hexo d - “ERROR Deployer not found git”

Install hexo-deployer-git

1
npm install hexo-deployer-git --save
閱讀全文 »

  • Bash lang-bash, lang-sh, lang-zsh

  • C, C++, and other C-likes lang-c, lang-h, lang-cpp, lang-hpp, lang-c++, lang-h++, lang-cc, lang-hh, lang-cxx, lang-hxx, lang-c-like

  • C# lang-cs, lang-csharp, lang-c#

    閱讀全文 »

command

Install Hexo

1
Install Hexo

Dump version

1
2
3
hexo version
// 新版修改
npx hexo version
閱讀全文 »

預先安裝 Git 和 Node.js

Install Hexo

1
npm install -g hexo-cli

Dump version

1
2
3
hexo version
// 新版修改
npx hexo version
閱讀全文 »

基本設定

Install Hexo

1
npm install -g hexo-cli

Dump version

1
2
3
hexo version
// 新版修改
npx hexo version
閱讀全文 »

npm WARN npm does not support Node.js v14.16.0 (windows)

刪除目錄

1
2
C:\Users\yourname\AppData\Roaming
目錄 npm and npm-cache

安裝npm

1
npm install -g npm@latest 

Cannot use import statement outside a module (node.js)

參考 Node.js v16.0.0 document type

package.json 加入 “type”: “module”,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"name": "node_test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hexo": "^5.4.0",
"hexo-theme-next": "^8.3.0",
"lodash": "^4.17.21",
"mathjs": "^9.3.2"
}
}

require is not defined (node.js)

package.json 移除 “type”: “module”,

process 參數含 & 要加 “ 才不會有問題

1
2
3
// index.js
console.log("---------")
console.log(process.argv[2])
1
2
3
4
5
6
7
8
9
10
11
$ node index.js &01
[35] 3164
bash: 01: command not found

$ node index.js &
[36] 15224

$ node index.js "&01"
---------
&01
[35]+ Stopped winpty node.exe index.js

process 參數含 ! 使用 “ 會有問題 要改為 ‘

1
2
3
4
5
6
node challeng.js "lv15?token={ILOVELIdemy!!!}"
bash: !}: event not found

node challeng.js 'lv15?token={ILOVELIdemy!!!}'
還真的是我猜的那樣...不過還是要謝謝你幫我們完成這麼多任務!
......

npm install 一直處於 sill install loadAllDepsIntoIdealTree

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 不知何時設定 https-proxy, 刪除即 ok
npm config get https-proxy
http://103.253.27.108:80/
npm config get proxy
null
npm config delete https-proxy
npm config list
; "builtin" config from C:\Users\win10\AppData\Roaming\npm\node_modules\npm\npmrc
prefix = "C:\\Users\\win10\\AppData\\Roaming\\npm"
; "cli" config from command line options
omit = []
user-agent = "npm/7.6.3 node/v14.17.0 win32 x64"
; node bin location = D:\app\nodejs\node.exe
; cwd = D:\work\git\test-npm
; HOME = C:\Users\win10
; Run `npm config ls -l` to show all defaults.

node.js server 中文亂碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 'Content-Type': 'text/html;charset=utf-8' 修正中文亂碼
// demo_module.js
var http = require('http');
var dt = require('./myfirstmodule');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'});
res.write("The date and time are currently: " + dt.myDateTime());
res.end();
}).listen(8080);

// myfirstmodule.js
exports.myDateTime = function () {
return Date();
};

found vulnerabilities-漏洞

  • 未找到一致解決方法

    9 vulnerabilities (4 low, 5 moderate)
    9 high severity vulnerabilities

body-parser 被標記為棄用(body-parser as deprecated)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 原來
const express = require("express");
const bodyParser = require("body-parser");
// app
const app = express();

app.use(bodyParser.json());


// 更新
const express = require("express");
// app
const app = express();

app.use(express.json());

Commans

Dump version

1
npm -v

ping npmjs registry

1
2
3
npm ping
npm notice PING https://registry.npmjs.org/
npm notice PONG 0.358ms

Dump all npm installed models

1
npm list
閱讀全文 »

基本

Dump version

1
node -v

simple run js

1
2
3
// app.js
var msg = "hello World";
console.log(msg);
1
node app.js

API 中文文件

OS

1
2
3
// test1.js
let os = require('os')
console.log(os.platform())
1
2
$ node test1.js
win32

HTTP

1
2
3
4
5
6
7
8
9
10
11
// http_server1.js
let http = require('http');
let server = http.createServer(handleRequest)

function handleRequest(req, res){
console.log(req.url)
res.write('hello')
res.end()
}

server.listen(5000);
1
2
3
$ node http_server1.js
/
/favicon.ico

Process

process存在於全域性物件上,不需要使用require()載入即可使用

1
2
// const process = require('process')
console.log(process.argv)

File system

1
2
3
4
5
6
7
8
9
10
// __dirname 為目前的目錄
let fs = require('fs')
console.log(__dirname)

fs.readFile(__dirname + '/bus921_temp.html', 'utf8',
(err, data) => {
parseBusData(data)
// console.log(data)
}
)

export my module

export #1

1
2
3
4
5
// myMouble.js - myModule export #1
function double(n) {
return n * 2
}
module.exports = double
1
2
3
// test1.js - myModule export #1
let myModule = require('./myModule')
console.log(myModule(3))
1
2
$ node test1.js
6

export #2 (常用)

1
2
3
4
5
6
7
8
9
10
11
12
13
// myMouble.js - myModule export #2
function double(n) {
return n * 2
}

var obj = {
double: double,
triple: function(n) {
return n * 3
}
}

module.exports = obj
1
2
3
// test1.js - myModule export #2
let myModule = require('./myModule')
console.log(myModule.double(3), myModule.triple(5))
1
2
$ node test1.js
6 15

HTPP server and client

request - - Simplified HTTP client

install
1
npm install request
show status
1
2
3
4
5
6
const request = require('request');
request('https://github.com/hot5656/AboutMe', function (error, response, body) {
console.error('error:', error);
console.log('statusCode:', response && response.statusCode);
// console.log('body:', body);
});
1
2
3
$ node request_1.js
error: null
statusCode: 200
get body
1
2
3
4
5
6
const request = require('request');
request('https://github.com/hot5656/AboutMe', function (error, response, body) {
// console.error('error:', error);
// console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
1
$ command node request_1.js  > ho5656.html
shwo header
1
2
3
4
5
const request = require('request');
request('https://github.com/hot5656/AboutMe', function (error, response, body) {
console.log(response.headers)
// console.log('body:', body);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ node request_1.js
{
server: 'GitHub.com',
date: 'Wed, 05 May 2021 07:45:16 GMT',
'content-type': 'text/html; charset=utf-8',
vary: 'X-PJAX, Accept-Encoding, Accept, X-Requested-With',
'permissions-policy': 'interest-cohort=()',
etag: 'W/"6c2b56ff86dccd4690557cb83915b549"',
'cache-control': 'max-age=0, private, must-revalidate',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'x-frame-options': 'deny',
'x-content-type-options': 'nosniff',
'x-xss-protection': '0',
'referrer-policy': 'no-referrer-when-downgrade',
'expect-ct': 'max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"',
'content-security-policy': "default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.g
ithub.com www.githubstatus.com collector.githubapp.com api.github.com github-cloud.s3.amazonaws.com github-production-re
pository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-u
ser-asset-6210df.s3.amazonaws.com cdn.optimizely.com logx.optimizely.com/v1/events wss://alive.github.com *.actions.gith
ubusercontent.com wss://*.actions.githubusercontent.com online.visualstudio.com/api/v1/locations insights.github.com; fo
nt-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.
githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com collector.githubapp.com github
-cloud.s3.amazonaws.com secured-user-images.githubusercontent.com/ *.githubusercontent.com; manifest-src 'self'; media-s
rc github.com user-images.githubusercontent.com/; script-src github.githubassets.com; style-src 'unsafe-inline' github.g
ithubassets.com; worker-src github.com/socket-worker-3f088aa2.js gist.github.com/socket-worker-3f088aa2.js",
'set-cookie': [
'_gh_sess=NI97SaBBGcExrVqC%2FAInwNqd%2FJ8kyr3QWl8aWLyXTQ02WCNaZnTA%2FBLbI9UUPfKJYc6dOc2J8Q9RObRql78r9q3D%2B5tLwpDh0j
a%2FGjn4WsjGm1XH1z7CWvkYyVQfOP%2FQx6n2pm95ePiwSwtITnj27BY7cteKvBzGlMKJNYqVuMzSXcxyMr9Tu4zVG99JDTU6oOOW1WQAPARk2t8Y%2F%2B
SLWBxcIAuEEAoBPH%2FoaBbI0G3IHtvvobWiCQodRvyeXJ30h0qui2ZQs8O8WNTsBdR4Jw%3D%3D--eZlEDQ1ebZKKm2Jh--H8LZRSxWEwmES%2F54qujq%2
Fw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax',
'_octo=GH1.1.1400842276.1620200716; Path=/; Domain=github.com; Expires=Thu, 05 May 2022 07:45:16 GMT; Secure; SameSi
te=Lax',
'logged_in=no; Path=/; Domain=github.com; Expires=Thu, 05 May 2022 07:45:16 GMT; HttpOnly; Secure; SameSite=Lax'
],
'accept-ranges': 'bytes',
'transfer-encoding': 'chunked',
'x-github-request-id': 'F317:1E82:12B4AA:163825:60924D0B',
connection: 'close'
}

http-server - node.js 內含

example
1
2
3
4
5
6
7
8
9
10
11
// http_server1.js
let http = require('http');
let server = http.createServer(handleRequest)

function handleRequest(req, res){
console.log(req.url)
res.write('hello')
res.end()
}

server.listen(5000);
1
2
3
$ node http_server1.js
/
/favicon.ico
example 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// http_server1.js
let http = require('http');
let server = http.createServer(handleRequest)

function handleRequest(req, res){
console.log(req.url)
if (req.url === '/') {
res.write('welcome')
res.end()
return
} else if (req.url === '/hello') {
res.write('hello')
res.end()
return
}else if (req.url === '/redirect') {
res.writeHead(200, {
'name': 'Robert'
})
res.end()
return
}else if (req.url === '/redirect2') {
res.writeHead(302, {
'location': '/hello'
})
res.end()
return
}
res.writeHead(404)
res.end()
}

server.listen(5000)
1
2
3
4
5
6
$ node http_server1.js
/
/hello
/redirect
/new
/redirect2

因 Chrome 使用 network monitor 有問題, 改用 Brave 正常

看不到 network monitor 是因為選JS(應選All)
總是有 util.js 和 pagejs.js 是因為 chrome 安裝了 SmartPKI 多憑證安控模組擴充套件