Home

Awesome

NPM version Build Status Coverage Status

Express middleware to open any file in an editor by request to defined route. Based on open-in-editor.

Install

npm install express-open-in-editor

Usage

var express = require('express');
var openInEditor = require('express-open-in-editor');

var app = express();

// There are few ways to setup:
// - to trigger middleware on *GET* request to `/open-in-editor`
app.get('/open-in-editor', openInEditor());

// - to trigger middleware on *any* request method to `/open-in-editor`
app.use('/open-in-editor', openInEditor());

// - to trigger middleware on *any* request method to *any* path
//   (not recommended unless server's single purpose is to open files in editor)
app.use(openInEditor());

After that you can use GET requests like /open-in-editor?file=foo/bar.ext:2:5 to open foo/bar.ext in an editor at line 2 column 5.

By default express-open-in-editor uses process.env.VISUAL or process.env.EDITOR (with this priority) to define the command to open a file in an editor. It could be set globally or on script execution:

EDITOR=subl node app.js

Also you can set process.env.OPEN_FILE that has highest priority and understands shorthands (i.e. subl for Sublime Text or atom for Atom Editor).

For more details about setup see open-in-editor description.

Using with webpack-dev-server

Although webpack-dev-server uses express to create a dev server, you have the same options to apply the middleware to it. The only difference is that you should define it inside onBeforeSetupMiddleware method:

const webpackConfig = {
  // ...
  devServer: {
    onBeforeSetupMiddleware(devServer) {
      devServer.app.use('/open-in-editor', openInEditor());
    }
  }
}

API

openInEditor([options]);

Options:

Related projects

License

MIT