Node.js Q&A

  1. What is NodeJs?

Node.js is an open source JavaScript run environment, which allows JS to be able to run on server side.


  1. Why Node.js?
  • Better ways to Organize Our Code into reusable pices.
  • Ways to deal with files
  • Ways to deal with Database
  • The Ability to communicate over the Internet.
  • The Ability to accept requests and send responses.
  • A way to deal with work that takes a long time.


  1. What is NPM?

npm is a package manager for Node.js.

  • Use npm install package to download a package.
  • Use require('package') to use.


  1. What is Express ?

Express is a web framework hosted within the Node.js runtime environment.


  1. Explain difference between blocking and non-bolcking in nodejs?

Blocking method execute synchronously, non-blocking method execute asynchronously.
Blocking is when the execution of additional Javascript in the Node.js process must wait until a non-javascript operation completes. This happens because the event loop is unable to continue running JavaScript while a blocking operation is occurring.


  1. What does package.json do?

package.json is a file specifies the basic information of a nodeJs project, including the general information(name, version...), dependencies, npm script, ect. I typically use it for project dependency management.
Use npm install / uninstall to add/ remove dependent libraries of the project.


  1. What is middleware in express?

Express middleware are functions that execute during the lifecycle of a request to the Express server. Each middllware has access to the HTTP request and response for each route(path) it attached to.
Additionally, middleware can either terminate the HTTP request(like a responnse being sent) or pass it on to another middleware function using next.

example: app.get(), app.use()

middleware order is important



8.What is "package-lock.json" in npm5?

package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json.
In other word, it is the history of your package.json.


  1. List HTTP methods you have used? Which are idempotent?
  • Idemponent : When making multiple identical requests has the same effect as making single request, then the request is idempotent.
  • POST is NOT idempotent.
  • GET, PUT, DELETE, HEAD, OPTIONS and TRACE are idempotent.
  1. How to design RESTFul web service? What is a resource?

REST architecture treats every content as a resource. These resource can be Text Files, Html Pages, Images, Videos, or Dynamic Busniess Data. REST Serve simply provides accesses to resource and REST client accesses and modifies these resources.

How to design:

  • Identify the objects which will be presented as resources.
  • Create the resource URIs
  • Assign HTTP methods


  1. What is Cross-Origin Resource Sharing(CORS)

CORS is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, but acccess to selected resources from a different origin.


CORS
  • We can set Access-Control-Allow-Origin on server side(cors) to solve CORS issues.

你可能感兴趣的:(Node.js Q&A)