Skip to content

Latest commit

 

History

History
119 lines (76 loc) · 4.49 KB

README.md

File metadata and controls

119 lines (76 loc) · 4.49 KB

Node.js examples from Bojinov's book

Node.js project Directory samples_Bojinov\ contains Node.js examples presented in Bojinov's book "RESTful Web API Design with Node.js" (Packt, 2015).

express Example

Command npm start executes application app\app.js which performs two tasks:

  • it starts the server application which listen to client requests on port 8180 (defined in file config.json).
  • it opens URL http:/127.0.0.1:8180 in our default web browser.
> cd
N:\samples_Bojinov\express
 
> npm start

> express-app@0.0.1 start N:\samples_Bojinov\express
> node ./npm_scripts/start_browser.js && node .


Module search path: (none)
Server listening on port 8180

The default browser displays the following contents in a new tab:

2019-12-07T17:53:06+01:00

hello-1 Example

Command npm start executes application app\app.js which performs two tasks:

  • it starts the server application which listen to client requests on port 8180 (defined in file config.json).
  • it opens URL http:/127.0.0.1:8180 in our default web browser.
> npm start

> hello1-app@0.0.1 start N:\samples_Bojinov\hello-1
> node ./npm_scripts/start_browser.js && node .

Node runtime: 16.20.2 (x64)
Module search path: (none)
Started Node.js http server at http://127.0.0.1:8180
requested (GET)

math Example

Command npm run test executes all test functions contained in directory math\test:

> npm run test

> math@0.0.1 test N:\samples_Bojinov\math
> nodeunit test

test-math
√ test_add
√ test_subtract

OK: 2 assertions (16ms)

mock Example

Command npm run test executes all test functions contained in directory mock\test, in this case test-http-module.js:

> npm run test

> mock-example@0.0.1 test N:\samples_Bojinov\mock
> nodeunit test

test-http-module
Request processing by http-module ended
√ test_handle_GET_request

OK: 0 assertions (184ms)

routes Example

Command npm start executes app\app.js which performs two tasks:

  • it starts the server application which listen to client requests on port 8180 (defined in file config.json).
  • it opens URL http:/127.0.0.1:8180/salut?name=tom in our default web browser.
> npm start

> routes-app@0.0.1 start N:\samples_Bojinov\routes
> node ./npm_scripts/start_browser.js && node .


Node runtime: 16.20.2 (x64)
Module search path: N:\samples_Bojinov\\node_modules
Server listening at 127.0.0.1:8180

mics/May 2024