API Resources for Node.js Developers
Javascript is already widely used inside browsers. The arrival of Node.js by Ryan Dahl combined with Google’s V8 Javascript engine pushed Node.js to be one of the most popular languages for writing non-blocking code to power HTTP APIs. Native JSON support along with light frameworks like express.js enabled Node.js to be a breeze for standing up quick APIs without the fuss of heavier frameworks.
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.
-
Node.js
- History of Node.js on Wikipedia
- Pros and Cons of Node.JS: understand why you want to use Node.JS
- Full Stack Javascript Developer is another reason for 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.
-
Asynchronous Programming
Asynchronous programming is another big feature of Javascript and Node.JS ecosystem. Start with understand callbacks, then work your way to Promises, and the new Async Await models in ES2017.
- 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.
- Generators in Javascript: Before learning await and async, understanding Generators can be very important.
- 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.
-
ExpressJS
The E in MEAN or MERN stack, ExpressJS is very popular amongst Node.JS developers.
-
Restify
As name suggests, it is designed for RESTful APIs.
-
Hapi
Hapi is the framework make by Walmartlabs.
-
Meteor
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
- Generating REST API from GraphQL
- Build a Node.js Middleware to Log HTTP API Requests and Responses
Tutorials for Deployment
-
Heroku
-
AWS
-
Azure
-
Google App Engine
Useful Libraries
The most popular package manager for node is NPM.
-
Documentation
- Swagger Node
- Swagger Express
- apiDoc - Inline documentation for RESTful web APIs.
-
Authentication
- passport.js - A full suite of authentication libraries.
- express-jwt -A middleware for checking JWT.
- express-x-hub - A middleware to protect your webhook endpoints.
- node-jsonwebtoken
-
CORS
- express cors - a CORS middleware for express.
-
Proxy
-
JSON
- body-parser - a standard JSON parsing middleware that comes with expressjs
- jsonfile - reading and writing JSON files.
-
Utilities
- Debug - manages debugging messages.
- SuperAgent - rest client
- node-uuid - generates uuid.
- winston - logging utility
- momentjs - best library for date and time.
-
Databases, Query Builder and ORMs
- Drivers
- 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.
- Other
-
REST
- 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.
-
GraphQL
- graphql-relay-js - supports relay requirements also.
- graphql-js - official implementation
- apollo-server - the most popular and easy to use tool for building GraphQL servers.
-
WebSockets
- 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)