Introducing: Pika CDN + Deno
Published: 2020-02-05 23:37:00

[Deno](https://deno.land/) isn't just for TypeScript, anymore! Did you know that you can also use Deno to import and run JavaScript packages from npm? 

As long as your package is written as [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) (JavaScript's native module syntax) and doesn't rely on any Node-specific behavior/imports, Deno can load and run JavaScript from any URL without breaking a sweat. Pika already hosts [a search catalog of 80,000+ ESM packages on npm](https://www.pika.dev/search) with more being added every day. 

All of this makes the [Pika CDN](https://www.pika.dev/cdn) -- our modern CDN for the npm ecosystem -- a great fit for Deno. With the Pika CDN, you can `import` any npm package from a single, hosted URL. This has always been a good fit for websites, but now it is an even better fit for Deno. That's because Deno has no package manager, so importing packages from URLs is already built in to the Deno workflow.

## Introducing "X-TypeScript-Types"

But what about type declarations? Deno is a TypeScript runtime, after all. It would be a shame if you couldn't also fetch the type declarations that exist inside of each npm package (or via the community-generated `@types/` project by DefinitelyTyped) whenever you import a JS npm package.

**Well, now you can!**

![Deno + Pika Example](https://dev-to-uploads.s3.amazonaws.com/i/mg12ls44h2kg89p6lxfu.png)

In collaboration with the Deno team for their recent v0.32.0 release, Pika CDN now hosts type declarations for every package that provides them! Import an npm package from our CDN and Deno will automatically fetch its type declarations along with it. 

 With this new feature, your programs get an extra level of stability with automatic warnings from Deno when a package is used incorrectly.

This is all thanks to Deno's new "X-TypeScript-Types" response header support. Here's how it works:

1. **Hosting the type declarations:** For Deno to read package type declarations, they have to exist somewhere on our CDN. We do the work at build-time to find the type files for your package and then host them at the `/types/*` package URL subpath.
2. **Telling Deno where to find them:** Each package on the CDN that has valid types responds with a `X-TypeScript-Types` header. When Deno sees this header from an import, it automatically fetches the types and connects them to the import.

If no type declarations exist on npm, we don't send the header. In that case, Deno will read the JS files and make its best guess at what its interface looks like. We could try to do the same on the CDN, but for now we feel pretty confident that Deno is better at this than we are :)

## Exciting Times!

None of this would have been possible without the efforts of [@kitsonk](https://twitter.com/kitsonk) and the entire team of [Deno contributors](https://github.com/denoland/deno). 

With these changes, [Pika CDN](https://www.pika.dev/cdn) is now THE BEST PLACE to get npm packages that run on Deno. This is something that we're extremely proud of, and a goal that we'll keep improving on as Deno works towards their v1.0 release. Exciting times, indeed!

We can't wait to see what you build with Deno and our CDN. [Reach out to us on Twitter](https://twitter.com/pikapkg) with any questions, comments, and links to what you've built.

✌️
\- [@fks](https://twitter.com/FredKSchott)