All Projects → artsy → Express Reloadable

artsy / Express Reloadable

Licence: other
Automatically hot-swap Express server code without the restart

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Express Reloadable

Express Routemap
Display all your express routes in the terminal!
Stars: ✭ 131 (+555%)
Mutual labels:  express, developer-tools
Flowmaker
flowmaker: JS to SVG flowchart generation extension for Vscode in realtime written in typescript and also download the SVG through local node server. Extension:
Stars: ✭ 108 (+440%)
Mutual labels:  express, developer-tools
Gulp Develop Server
Development assistant for node.js server by gulp
Stars: ✭ 72 (+260%)
Mutual labels:  express, developer-tools
Giraffql
Interactive GraphQL exploration tool built with React - still working on the website
Stars: ✭ 176 (+780%)
Mutual labels:  express, developer-tools
Curlie
The power of curl, the ease of use of httpie.
Stars: ✭ 877 (+4285%)
Mutual labels:  developer-tools
Vue Qq
🎨 Vue family bucket with socket.io and express/koa2 , create a web version of mobile QQ, supporting real-time group chat, real-time private chat, special care, shielding chat, smart IP geographic location, real-time display temperature and other QQ core functions
Stars: ✭ 861 (+4205%)
Mutual labels:  express
Jx3store
An online game item store built by express and materialize
Stars: ✭ 10 (-50%)
Mutual labels:  express
3ree
An example universal JS application written with the 3REE stack, React + Redux + RethinkDB + Express. A stack for building apps, front and back end, with just Javascript.
Stars: ✭ 856 (+4180%)
Mutual labels:  express
Shopify Mern Boilerplate
A Boilerplate for creating MERN stack Shopify app.
Stars: ✭ 20 (+0%)
Mutual labels:  express
Angela
🙂angela (安其拉):react ssr router redux; react同构框架
Stars: ✭ 15 (-25%)
Mutual labels:  express
Node Js Getting Started
Getting Started with Node on Heroku
Stars: ✭ 872 (+4260%)
Mutual labels:  express
Gita
Manage many git repos with sanity 从容管理多个git库
Stars: ✭ 865 (+4225%)
Mutual labels:  developer-tools
Majestic
⚡ Zero config GUI for Jest
Stars: ✭ 7,261 (+36205%)
Mutual labels:  developer-tools
Deprecated
🚀 Framework for building universal web app and static website in Vue.js (beta)
Stars: ✭ 858 (+4190%)
Mutual labels:  express
Chromelogger
chrome extension for server side console logging
Stars: ✭ 884 (+4320%)
Mutual labels:  developer-tools
Node Auth
基于 Node Express Mongoose 实现的用户注册/登陆权限验证
Stars: ✭ 10 (-50%)
Mutual labels:  express
Docker Nginx Express
🐳 A playground for Docker with Nginx and Express.
Stars: ✭ 13 (-35%)
Mutual labels:  express
Express Starter
Express Starter
Stars: ✭ 14 (-30%)
Mutual labels:  express
Typescript React Express
typescript react express example
Stars: ✭ 12 (-40%)
Mutual labels:  express
Webpack2 Express Heroku Starter
Starter app using Webpack 2, Express, setup to deploy to Heroku.
Stars: ✭ 12 (-40%)
Mutual labels:  express

@artsy/express-reloadable

When developing a Node app it's common to rely on tools like node-dev or nodemon to make the development process more rapid by automatically restarting the server instance on file-change. What express-reloadable does is listen for source-code changes within a subset of your app and, scanning Node's internal module cache, clears the require call if found. This tricks Node into thinking the module has not yet been loaded, effectively hot-swapping out your code without a full restart. Additionally, when the watchModules option is passed, express-reloadable will listen for changes to NPM module code and reload on change. Useful when working with yarn link across packages / repos. Crazy-fast development speed!

(Disclaimer: While this works for most of our use-cases, this is an example of "require hacking" and hasn't been tested in all environments. Your mileage may vary :)

How it works:

  • express-reloadable is called with a path to an app, which it then mounts
  • When source-code within that folder / app changes an internal lookup is made to Node, scanning its require cache for the changed file
  • If found, it is cleared internally via delete require.cache[id]
  • When a new request is made express-reloadable executes a callback that re-requires the code and changes are instantly available.

Installation:

yarn add @artsy/express-reloadable

Example:

The below example assumes that the folders /api and /client exist, and that each contain an index file that exports a mountable express.js route.

import express from 'express'
import { createReloadable, isDevelopment } from '@artsy/express-reloadable'

const app = express()

if (isDevelopment) {

  // Pass in `app` and current `require` context
  const mountAndReload = createReloadable(app, require)

  // Pass in the path to an express sub-app and everything is taken care of
  mountAndReload(path.resolve(__dirname, './client'))

  // Full example:
  app.use('/api', mountAndReload(path.resolve(__dirname, './api')), {

    // If you need to mount an app at a particular root (`/api`), pass in
    // `mountPoint` as an option.
    mountPoint: '/api',

    // Or if you're using `yarn link` (or npm) to symlink external dependencies
    // during dev, pass in an array of modules to watch. Changes made internally
    // will be instantly available in the app. Additionally, using something like 
    // `glob`, other modules outside of express route path can be passed.
    watchModules: [
      '@artsy/reaction',
      '@artsy/artsy-xapp'
    ]
  }))

  // If prod, mount apps like normal
} else {
  app.use('/api', require('./api')
  app.use(require('./client')
}

app.listen(3000, () => {
  console.log(`Listening on port 3000`)
})

Troubleshooting:

Help! I've mounted my app using reloadable but I'm not seeing any changes?

For the utility to work you need to a) ensure that NODE_ENV=development (for safety) and b) the path to your app is absolute:

// Incorrect
app.use(reloadAndMount('./path/to/app'))

// Correct :)
app.use(reloadAndMount(path.resolve(__dirname, 'path/to/app')))

Thanks:

This package was heavily inspired by @glenjamin's ultimate-hot-loading-example.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].