Skip to content

Latest commit

 

History

History

01_node

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

NodeJS library import example

Consumes es2015-publish-template project using npm via github registry and lodash via npm

##Running this example Make sure you have typings installed globally first

npm install typings -g
npm install
typings install
node app.js

Mechanisms utilized

  • npm
    • github registry
    • npm registry
  • typings
    • lodash

Scenario

The key takeaway with this example is we are able to display intellisense module "d.ts" declaration files within our IDE. For lodash, we can rely on the public "typings" registry. Simple enough right? What about our own library project?

Stepping out of this example project, let's pretend we're about to publish our library for the world to consume. We'd like to generate a d.ts definition file for coding ease. Here are some popular options:

  1. upload to DefinitelyTyped for eventual consumption via command "tsd"
  2. upload to the typings registry for eventual consumption via command "typings"
  3. keep it within our source, exposed within package.json's "typings" property

It turns out, option 1 is deprecated as mentioned here. Option 2 might be nice if we had a large, heavily relied upon public codebase and we were willing to undergo submission collaboration. This example actually relies on option 2 for loading lodash definitions. Option 3 looks most reasonable for our small library.

Option 3 is pretty simple too. It's just one step. From library project to be published, point package.json "typings" property to your generated index.d.ts

{
    "typings": "dist/es2015/index.d.ts"
}

That's it! Packages deployed with the "typings" property will enable the IDE to provide helpful intellisense.