JavaScript Everywhere

Reusing code in Node, Web, and Mobile

Rafael Rozon
7 min readJul 16, 2018

In this tutorial, I’ll show you how to set up a JavaScript monorepo with an api (Express), a web app (React), a mobile app (React Native), and a shared folder for reusable code. But first…

A brief introduction

I’m a software developer and most part of my time is spent building REST APIs and React applications. My journey with monorepos started first as a curiosity. And then it became more serious when I started building my own app a few months ago. When I started building this app I had some basic principles that I wanted to follow as much as possible:

  1. Use JavaScript for the entire stack
  2. Avoid duplicating business logic between backend and frontend
  3. Easy setup and maintenance

The main parts of the stack were: an api server (GraphQL/Node), a web app (React), and a mobile app (React Native).

The main focus of this article is specially related to the second item above. Having the whole stack as a monorepo allowed me to share code between my api server, the web app, and the native app. What follows next are some of the discoveries I had along the way and how I set up my project. I hope you enjoy it.

Trial and Error

In my quest for a monorepo setup, I tried a few methods and tools including:

--

--

Rafael Rozon
Rafael Rozon

No responses yet