Today, I'm very pleased to reveal that we've been working on making micro 1000% smaller and 22% faster - therefore making it perform much better in production.

In addition, we're introducing micro-dev, a new package that takes over all of the features that only exist for the matter of developing microservices easier - allowing micro to focus entirely on the production environment.

Here's what has changed:

micro

From now on, you should only use this package in the production environment. This will result in a faster microservice, better installation times and less memory and disk space used.

As an example, here's a comparision of the dependencies used in micro:

In addition to making micro more lightweight, we also made it perform better.

As tested with the Apache's HTTP benchmarking tool on a iMac with 32GB RAM, a quad-core i5 3.2 GHz processor, we were able to determine that the number of requests per second changed from around 3,580 to about 4,400 for this example service:

module.exports = () => 'Hello world'

10,000 requests were performed - as defined by this command (you can try it by yourself):

ab -n 10000 http://localhost:4000/

All of these changes lead to micro now being much more suitable for being used in production: All of the features that make development easier (like automatic port selection, copy-to-clipboard and pretty logging messages) aren't included in the core anymore and are therefore not slowing the setup of your microservice down.

micro-dev

This package is new. It's meant to be used only in the development environment, not in production and includes all of the features (and even more) that let you create microservices in no time and with ease.

In addition to micro's capabilities, it comes with the following improvements:

Hot Reloading

When you make changes to your code, the server will restart automatically:

Logs

Incoming and outgoing requests will be logged to stdout. When JSON bodies are logged, they will be prettified automatically. If any exceptions are thrown, errors will also be styled and made human-readable.

Even the duration is shown for each request:

Automatic Port Selection

If the port defined (or the default one) is already used by a different application, a open one will be selected.

Clipboard Support

The local address of your microservice will be copied to the clipboard automatically, so that you can paste it into a different application in order to test your code. This only happens in TTY mode.

Your New Setup

Now that you know what has changed, I'll explain how you can set up both tools for a new microservice.

Firstly, you need to ensure that both packages are installed. Since micro needs to be available in the production environment, it needs to be installed using the --save flag (can be left away since npm 5):

npm install --save micro

Next, micro-dev (which will be used for development) should be installed like this:

npm install --save-dev micro-dev

Once you've run these two commands, you've installed everything necessary. In turn, you can now modify the package.json file and define which package to run in which environment:

{
  "scripts": {
    "start": "micro",
    "dev": "micro-dev"
  }
}

As the final step, create the index.js file and insert a microservice. Here's an example:

module.exports = () => 'Hello world'

Done! The next time you want to continue writing on your microservice code, run this command (which will run micro-dev):

npm run dev

When running your code in production, please configure your deployment setup so that the npm start (which runs micro) will be run. If you're deploying using now, this will happen automatically.

Deploying With Now

You need to set the NODE_ENV environment flag to "production", so that thedevDependencies (which includes micro-dev) won't be installed on the server. Otherwise the installation step won't be faster than before.

Contribute

Both micro (the changes were introduced in this pull request) and micro-dev are open source and MIT-licensed. Feel free to report bugs or suggest features! Help is greatly appreciated.