The document discusses Jakarta JS and provides an overview of basic Node.js concepts including RESTful APIs, Express, Mongoose, and testing with Mocha, Should, and Supertest. It includes code snippets and instructions for setting up a simple RESTful Node.js application with Express, MongoDB via Mongoose, and testing.
How to Troubleshoot Apps for the Modern Connected Worker
Javascript Basic RESTful
1. Jakarta JS
Back to Basic of Node.js and Reactivity
RESTful API with Node.js + MongoDB
2. About Me
• Name : Sofian Hadiwijaya
• Email : me@sofianhw.com
• Blog : http://www.sofianhw.com
• Id : sofianhw
3. Basic - RESTful
Wikipedia, that infallible source, defines
Representational State Transfer (REST) as: an
architectural style that abstracts the architectural
elements within a distributed hypermedia system.
4. Basic - RESTful
Four basic design principles from IBM's developerWorks website
1.Use HTTP methods explicitly
2.Be Stateless
3.Expose directory structure-like URIs
4.Transfer XML or JSON, or Both
5. Basic - Express JS
A minimal and flexible node.js web application framework, providing a
robust set of features for building full web applications and/or APIs.
$ npm install express
• Middleware
• Routing
7. Basic - Express
A router object is an isolated instance of middleware and routes,
capable only of performing middleware and routing functions.
A router behaves like middleware itself, so you can use it as an
argument to app.use() or as the argument to another router’s use()
method.
Every Express application has a built-in app router:
8. Basic - Express
Chainable route handlers for a route path can be created using app.route().
Since the path is specified at a single location, it helps to create modular
routes and reduce redundancy and typos.
14. Basic Testing - Mocha
Mocha is a simple, flexible, fun JavaScript test framework for node.js and
the browser.
$ npm install -g mocha
15. Basic Testing - Should
should is an expressive, readable, framework-agnostic assertion library. The
main goals of this library are to be expressive and to be helpful. It keeps your test
code clean, and your error messages helpful.
$ npm install should
16. Basic Testing - Supertest
HTTP assertions made easy via super-agent
$ npm install supertest