Skip to content

Instantly share code, notes, and snippets.

@robinedman
Last active July 9, 2018 15:05
Show Gist options
  • Save robinedman/55afbffc10ba6db1326ee026aa44b8a7 to your computer and use it in GitHub Desktop.
Save robinedman/55afbffc10ba6db1326ee026aa44b8a7 to your computer and use it in GitHub Desktop.
Getting started: Node.js and related technologies

Getting started with Node.js development

Installing

Install nvm for managing versions. This allows you to install and switch between different Node versions.

Then install the latest version of Node with:

nvm install stable

To check which version you're using:

node --version

Editor config

You'll want to install the following extensions for your editor:

  • eslint to check your code for common errors as you type (settings are configured on a per repo basis through an .eslintrc file)
  • Prettier to format your code. If we run this before PRs we don't have to argue about code formatting in PRs.

I like VS Code a lot. Has "IDE like" features for navigating code easily.

Coding Style

BC JavaScript Style Guide forked from the AirBnb guide.

JavaScript/Node resources

Node

GraphQL development in Node

  • graphql-tools from the Apollo dev team: "GraphQL Tools is an npm package and an opinionated structure for how to build a GraphQL schema and resolvers in JavaScript, following the GraphQL-first development workflow."
  • graphql-tools example app. Express app including authentication with Passport.
  • dataloader from Facebook providing "a consistent API over various backends and reduce requests to those backends via batching and caching". You'll want to use this for code that goes into production.

General JS

Packages

There is a philosophy "do one thing well" and of reusing code whenever possible. There are bigger packages but also a lot of small packages.

Finding packages

There are some obvious packages to use for some things. Such as:

  • Lodash. JS has a smaller standard library than most languages. Lodash is the go-to for utility functions. Just make sure to check that the function you're using isn't included in JS already.
  • Express is the most popular Node.js framework with the largest community. It extends Node making it more convenient for developing typical web applications. The framework is minimalistic. Functionality is added to it via other packages, which often come in the form of "middleware". Alternatives are Koa and hapi.
  • Passport for authentication.
  • AVA for unit testing.

Role management/access control: https://gist.github.com/facultymatt/6370903

When you don't know https://www.npmjs.com/ is the best place to start. Then evaluate the GitHub repo:

  • Are there unit tests?
  • Is the code good quality?
  • How popular is it?
  • Is it well maintained? (Note: Sometimes packages are so small that they are "complete" and maintenance isn't really necessary.)
  • How is the documenation?
  • Etc etc. The usual evaluating open source sofware deal...

MongoDB

  • As a concise intro I like The Little MongoDB Book. It explains NoSQL/MongoDB concepts and the rationale for them in a pedagogical way. It's a much gentler introduction than the official docs.
  • There are official online courses for free at https://university.mongodb.com/

There are various abstractions one can use on top of Mongo. As the query interface is actually in JavaScript I'd say it makes sense to at least initially stay "close to the metal" so as to understand what you're doing. You don't need an ORM as you don't have the object oriented vs relational model mismatch.

@simonyeldon
Copy link

apollo or relay?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment