今天進度 : Build your Node image | Docker Documentation
test@test:~$ mkdir demo; cd demo;
test@test:~/demo$ sudo apt install npm
test@test:~/demo$ npm init -y
Wrote to /home/test/demo/package.json:
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
test@test:~/demo$ npm install ronin-server ronin-mocks
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN demo@1.0.0 No description
npm WARN demo@1.0.0 No repository field.
+ ronin-mocks@0.1.6
+ ronin-server@0.1.3
added 110 packages from 68 contributors and audited 110 packages in 91.037s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
test@test:~/demo$ touch server.js
test@test:~/demo$ nano server.js
GNU nano 4.8 server.js Modified
const ronin = require( 'ronin-server' )
const mocks = require( 'ronin-mocks' )
const server = ronin.server()
server.use( '/', mocks.server( server.Router(), false, true ) )
server.start()
今天安裝 npm 發現安裝真多東西...
啟用 node server
test@test:~/demo$ node server.js
之後開另外一個 ssh 視窗發請求測試看看
test@test:~$ curl --request POST \
> --url http://localhost:8000/test \
> --header 'content-type: application/json' \
> --data '{
> "msg": "testing"
> }'
{"code":"success","payload":[{"msg":"testing","id":"14a38255-e434-4563-bf4e-4685fa6c8802","createDate":"2020-10-04T18:10:36.437Z"}]}
test@test:~$ curl http://localhost:8000/test
{"code":"success","meta":{"total":1,"count":1},"payload":[{"msg":"testing","id":"14a38255-e434-4563-bf4e-4685fa6c8802","createDate":"2020-10-04T18:10:36.437Z"}]}
原 ssh 視窗 log
test@test:~/demo$ node server.js
2020-10-04T18:10:36:4080 INFO: POST /test
2020-10-04T18:12:21:8400 INFO: GET /test