npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

open-in-editor-connect

v1.0.0

Published

Open in editor middleware

Downloads

82

Readme

open-in-editor-connect

NPM Version Linux Build Windows Build Test Coverage Known Vulnerabilities

Connect/Express extension to open a local file in an editor by URL. It could be useful addon for a local development server.

Editor support:

You also can use any other editor that is able to open files from command line.

Features

  • Quickly open a local file in an editor from the browser. Just append line number to the URL.
  • Easy to use with open-in-editor-extension for Google Chrome.
  • X-SourcePath HTTP header with a local path on a file system.
  • Built-in adapter for the serve-static middleware.
  • Configurable editors

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install open-in-editor-connect

Then add the middleware to your server. There are some examples the below how to use open-in-editor-connect middleware for a web server.

Usage

Append line number to the URL in the location bar of a browser and a file will be opened in the editor.

open-in-editor-connect

Examples

curl -X POST -i "http://localhost:3000/server.js:123"

Open the server.js file in default editor and put a cursor to line 123.

curl -X POST -i "http://localhost:3000/server.js?edit=sublime&at=123"

Open the server.js file in Sublime Editor and put a cursor to line 123.

URLs

  • http://host/path:{line}
  • http://host/path:{line}:{column}

Query Parameters

edit

  • http://host/path?edit
  • http://host/path?edit={editor}

API

var openInEditor = require('open-in-editor-connect');
  • openInEditor(root, options)

Create a new middleware function to handle files from within a given root directory.

If root is not provided then it returns new middleware factory where the given options will be set to defaults.

root

The file to handle will be determined by combining req.url with the provided root directory.

Options

dotfiles

Set how "dotfiles" are treated when encountered. Default is ignore.

  • allow No special treatment for dotfiles.
  • ignore Pretend like the dotfile does not exist and 404/next().

editorParam

String name of query param. Default is edit.

serveStatic

Set this to true to return a wrapped version of for the serve-static middleware. The main proporse of the wrapping is an ability to open in an editor the same files as they served. Also the wrapper adds X-SourcePath HTTP header to the served files response. Default is false.

The serve-static isn't a dependency of open-in-editor-connect. The dependencies section of your application's package.json file must contain the serve-static module in order to use the wrapper.

editor

Object with options for an editor.

name: An string name of an editor.

Supported names are:

| Name | Editor | | -------------- | ------------------------------------------- | | atom | Atom Editor | | emacs | Emacs (via Terminal, Mac OS and Linux only) | | idea14ce | IDEA 14 CE | | phpstorm | PhpStorm | | sublime | Sublime Text | | vim | Vim (via Terminal, Mac OS and Linux only) | | visualstudio | Visual Studio | | webstorm | WebStorm |

Use these setting if the editor currently is not supported or if the editor's path can't be detected automatically.

binary: A string path to the editor binary

args: A string of command line arguments which will be passed to the binary. The args can contain placeholders to be replaced by actual values. Supported placeholders: {filename}, {line} and {column}

terminal: Set this to true if the editor should be opened in a terminal. Mac OS and Linux are supported.

Examples

Connect: Open in Visual Studio Code

var connect = require('connect');
var serveStatic = require('serve-static');
var openInEditor = require('open-in-editor-connect');

var app = connect();
app.use(openInEditor('.', {
  editor: { name: 'code' }
}));
app.use(serveStatic('.'));
app.listen(3000);

License

MIT

For more information

Enjoy!

Copy Markdown