In fact, our analytics data shows Node.js as being the most popular language for creating REST and GraphQL APIs. The explosive growth in React and Single Page Apps has added fuel to the growth of Node.js for creating APIs. It’s event driven model make it a perfect candidate for building serverless apps on platforms like AWS lambda.
Background on Node.js and Key Concepts
Sometime is worth understanding the motivation and history of Node.JS. And the key motivation (compared to previously techniques), especially regarding Non Blocking IO and asynchronous techniques.
- History of Node.js on Wikipedia
- Pros and Cons of Node.JS: understand why you want to use Node.JS
Non Blocking IO
This is key reason that Node.JS is saves computing cycles compared to blocking frameworks such as PHP. Often times, it is not code running time, it is the IO, i.e. reading or writing from file system, databases, or networks that are bottlenecks.
- Understand Callbacks: Callback is probably easiest starting point for async programming.
- Promises: Similar to a concept called Futures in other languages, Promises is another layer of abstraction that makes manage async programming easier.
- Async Await: It is actually first popularized in C#. This way of handling async programming can be even easier to understand.
- Comparing Async Await vs. Promises
Tutorials for Creating RESTFul APIs
Like most web pages, you usually build APIs on tops of an existing framework (especially for routing). So the tutorials below are organized by framework.
The E in MEAN or MERN stack, ExpressJS is very popular amongst Node.JS developers.
As name suggests, it is designed for RESTful APIs.
Hapi is the framework make by Walmartlabs.
Meteor is more of a full stack framework, but you can also create RESTful APIs.
Tutorials for Creating GraphQL APIs
GraphQL is promoted as an alternative to RESTful API, you can read more about the background on GraphQL, and other types of APIs here.
- Tutorial from HowToGraphQL
- Basic GraphQL server in Express
- Official tutorial from Apollo
- A more in-depth tutorial
- A website dedicated to learning Apollo.Js
Tutorials for Deployment
Google App Engine
The most popular package manager for node is NPM.
- express cors - a CORS middleware for express.
Databases, Query Builder and ORMs
- ODM / ORM
- Sequelize - Multi-dialect ORM. Supports PostgreSQL, SQLite, MySQL.
- Bookshelf - ORM for PostgreSQL, MySQL and SQLite3 in the style of Backbone.js.
- Massive - PostgreSQL data access tool.
- Mongoose - Elegant MongoDB object modeling.
- Waterline - Datastore-agnostic tool that dramatically simplifies interaction with one or more databases.
- Iridium - MongoDB ORM with support for promises, distributed caching, preprocessing, validation and plugins.
- OpenRecord - ORM for PostgreSQL, MySQL, SQLite3 and RESTful datastores. Similar to ActiveRecord.
- orm2 - ORM for PostgreSQL, MariaDB, MySQL, Amazon Redshift, SQLite, MongoDB.
- firenze - Adapter-based ORM for MySQL, Memory, Redis, localStorage and more.
- pg-promise - PostgreSQL framework for native SQL using promises.
- Objection.js - Lightweight ORM built on the SQL query builder Knex.
- Query builder
- Knex - Query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.
- Frisby - a test framework for REST APIs.
- Facet - extensible, framework agnostic JSON API platform for Node.js
- Restful - a REST client library.
- hello.js - a REST client library that support OAuth2.
- Interfake - Rapid prototyping framework for making mock HTTP APIs, with a Node.js, command-line and HTTP interface.
- ThinkJS - Framework with ES2015+ support, WebSockets, REST API.
- ActionHero - Framework for making reusable & scalable APIs for TCP sockets, WebSockets, and HTTP clients.
- LoopBack - Powerful framework for creating REST APIs and easily connecting to backend data sources.
- restify-mongoose - Generate RESTful API based on your mongoose schema.
- Socket.IO - Featuring the fastest and most reliable real-time engine.
- Nodejs-websocket - Node.js module for websocket server and client.
- WebSocket-Node - WebSocket Implementation for Node.JS (Draft -08 through the final RFC 6455).
- Sockjs-node - WebSocket emulation - Node.js server.
- Ws -
ws: The fastest cross platform RFC-6455 WebSocket implementation for Node.js.
- deepstream.io - Open realtime server a fast, secure and scalable realtime server for mobile, web & iot.
- websocket-as-promised - Promise-based W3C WebSocket wrapper: allows to use promises when connecting, disconnecting and messaging with WebSocket server.
- faye-websocket-node - Standards-compliant WebSocket client and server.
- ws-wrapper - Lightweight WebSocket wrapper that provides a socket.io-like event-handler API along with Promise-based requests.
- ws-server-wrapper - Companion library for ws-wrapper for the server-side.
- uws - Tiny WebSockets (access to the C++ library, µWebSockets, via Node.js)