Show Menu
Cheatography

NPM Module/Library Publishing & Testing Cheat Sheet (DRAFT) by [deleted]

All info in this cheat sheet is based on the lesson given in the following youtube video: https://www.youtube.com/watch?v=N55jHr9qzpg

This is a draft cheat sheet. It is a work in progress and is not finished yet.

NPM/Node Commands

npm init
Creates the package json file that contains all inform­ation of your node app, depend­encies, startup code, and other options. All node packages or apps NEED this file
 

module.ex­ports = ...

Module.ex­ports is a special object that is used as a container to hold all your code to be distri­buted as a node package. Distri­buted as in an actual package that can be published to npm and be downlo­adable from anywhere. You may also choose to have a package be local package.

Whatever code you want to be contained in a distrutbal node package must be assigned to the module.ex­ports object.

Examples:

// filename: module.js;

// packag­e-name: exampl­e-m­odule

module exports = functi­on(­nam­e){­con­sol­e.l­og(`Hi there ${name­}!`)};


// app.js

const func = requir­e('­exa­mpl­e-m­odu­le');


OR

// module.js

module exports = functi­on(­nam­e){­con­sol­e.l­og(`Hi there ${name­}!`)};