express-open-in-editor

3.1.1 • Public • Published

NPM version Build Status Coverage Status Dependency 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 server, you have the same options to apply the middleware to it. The only difference is that you should define it in setup method (see issue for details).

var server = new WebpackDevServer(webpack(config), {
  // ...
  setup: function(app) {
    app.use('/open-in-editor', openInEditor());
  }
});

API

openInEditor([options]);

Options:

  • cwd

    Type: String
    Default: '' (uses process.cwd())

    Working directory used when resolving paths.

  • Rest options are passing to open-in-editor as is.

Related projects

  • open-in-editor – package that do the main task of express-open-in-editor, i.e. opens file in editor.
  • babel-plugin-source-wrapperBabel plugin that instruments source code to associate objects with location they defined in code base.
  • Component Inspector – developer tool to inspect components that can open component creation source location in editor. Has integrations for React, Backbone and can be adopter for other frameworks.

License

MIT

Package Sidebar

Install

npm i express-open-in-editor

Weekly Downloads

76

Version

3.1.1

License

MIT

Last publish

Collaborators

  • lahmatiy