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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vscode-express

v1.0.1

Published

Create an HTTP server in VS Code for user interface of VS Code extension.

Downloads

206

Readme

vscode-express

Use webview in VS Code for user interface of VS Code extension.

Get Started

Install

npm install vscode-express --save

Import and Initialize

import * as vscode from 'vscode';
import {VSCExpress} from 'vscode-express';

export function activate(context: vscode.ExtensionContext) {
    // initial vscode express
    // 'view' is the ABSOLUTE root path of the web view in the extension
    const vscexpress = new VSCExpress(context, 'view');
    // register command
    context.subscriptions.push(vscode.commands.registerCommand('extension.vscexpress', () => {
        vscexpress.open('index.html', 'VS Code Express Example', vscode.ViewColumn.One);
    }));

    // rest code...
}

In Web

Insert script below in your web page:

const callbackStack = [];
const vscode = acquireVsCodeApi();

function command(cmd, callback) {
  if (!cmd) {
    return;
  }
  let args = Array.from(arguments);
  if (typeof args[args.length - 1] === 'function') {
    callback = args[args.length - 1];
    args.length = args.length - 1;
  } else {
    callback = undefined;
  }
  args.shift();
  const messageId = new Date().getTime() + Math.random();
  
  callbackStack.push({
    messageId,
    callback
  });

  vscode.postMessage({
    messageId,
    command: cmd,
    parameter: args
  });
}

window.addEventListener('message', event => {
  const message = event.data;

  for (let index = 0; index < callbackStack.length; index++) {
    const callbackItem = callbackStack[index];
    if (callbackItem.messageId === message.messageId) {
      if (callbackItem.callback) {
        callbackItem.callback(message.payload);
      }
      callbackStack.splice(index, 1);
      break;
    }
  }
});

And call VS Code command with command function. Such as:

command('extension.sayHello');

You can also do something after the command executed with callback:

command('extension.sayHello', function(res) {
    // res.code === 0 with success,
    // res.message is error message if error occurred
    // do something
});

If you need pass parameter to the command, send it with command:

command('extension.command', 'arg1', 'arg2', callback);

location Object Access for Web

Generally, you can pass some initial data with location.search or location.hash to JavaScript in web. The VS Code webview doesn't support search or hash as it uses file system to open the file you request. As a workaround, you can use a built-in variable of VSCExpress, _location to accesee location.search, location.hash and location.href.

Thus, you need to change your origin code a bit:

const href = _location ? _location.href : location.href;

Note: Different from location, _location has only search, hash and href property.

CORS and Open Links in Browser

Unfortunately, VS Code webview doesn't support CORS. However, it's not hard to make a workaround by using message passing. You can register the action to fetch remote content (with request module or something else) as a VS Code command, and call the action with command function mentioned above in the web.

vscode.commands.registerCommand('myExtension.httpRequest', async (uri: string) => {
  return await request(uri);
});

Open links in browser is similar:

vscode.commands.registerCommand('myExtension.openUri', (uri: string) => {
  vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(uri));
});

Example

https://github.com/Sneezry/vscode-express-example

Build from Source

git clone https://github.com/Sneezry/vscode-express.git
cd vscode express

And you need add prepare script in package.json for npm install:

  ...
  "fix": "gts fix",
  "prepare": "node ./node_modules/vscode/bin/install"
}

Then run npm install

npm install
npm run compile

To run the example, compile the code first, then open the example folder with VS Code:

code example

In VS Code, press F5 to start debug.

License

MIT License