Skip to content

ryanvmai/javascript_library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

What is NPM?

NPM stands for Node Package Manager. It serves as a free package registry accessible to anyone, making it easier to share javascript packages with others. Users usually interact with NPM in two ways: as someone downloading a package and someone publishing a JavaScript package.

Sources

W3Schools

Understanding Node.js Modules

What is a module?

A module is basically a JavaScript library which would contain a set of functions that you want to include in your code.

Node.js has many built-in modules that you can simply use without installing anything. A list of modules can be found here.

Including modules in your own code

To use a module in your code, use the function require().

var http = require('http')

The require() function reads a JavaScript file, executes it, and then returns the exports object. The exports keyword makes properties and methods available outside of the module file.

Example

Create a module that returns the current date and time.

exports.myDateTime = function () {
  return Date();
};

Use this module in a Node.js file

var dt = require('./myfirstmodule');

We use the ./ here to locate the module because the module is located in the same file as the Node.js file.

Sources

W3Schools

NodeJS

Creating index.js and package.json

Publishing and Installing

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published