//shapes/circle.js class Circle { //code here } exports.Circle = Circle
//circle-user.js const {Circle} = require('shapes/circle'); //Class Circle is now available for use using normal js code.
{1"name": "@ashafoo/shapes", "version": "1.0.0", "description": "Sample", "keywords": ["package sample", "basic sample"], "homepage": "https://github.com/asha-foo/shapes#readme",2"main": "index.js",3"module": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git+https://github.com/asha-foo/shapes.git" }, "author": "af", "license": "ISC", "private": false, "devDependencies": {}, "directories": { "test": "test" }, "bugs": { "url": "https://github.com/asha-foo/shapes/issues" } }
//index.js1//Importing const {Circle} = require('./shapes/Circle.js'), {Rectangle} = require('./shapes/Rectangle.js'), {RectangleSet} = require('./shapes/RectangleSet.js');2//Exporting exports.Circle = Circle; exports.Rectangle = Rectangle; exports.RectangleSet = RectangleSet;
dependencies": {
"@ashafoo/shapes": "^1.0.0
# using package.json > npm install # alternatively # explicit (will update package.json for you) > npm install @ashafoo/shapes
//my-test.js const {Rectangle, Circle, RectangleSet} = require('@ashafoo/shapes');