New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dl6

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dl6

Dynamic Loading Module (by ES6 Proxy)

latest
npmnpm
Version
0.3.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

dl6 -- Dynamic Loading Module for Node.js

dl6.require() delay the loading until the first time you call it.

dl6.require() reload your module automatically when the module is modified !

We use the es6 proxy and fs.watch() to implement the dl6 package.

Install

$ npm i dl6

Example

File: dl6ex.js

const dl6 = require('dl6')
const fs = require('fs')

function sleep (ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function main () {
  fs.writeFileSync('cat.js', `
  module.exports = {
    say: () => 'meow'
  }
  `)

  const cat = dl6.dload(__dirname, 'cat')
  console.log('cat=', cat)
  console.log(cat.say())
  console.log('cat=', cat)

  fs.writeFileSync('cat.js', `
  module.exports = {
    say: () => 'hello'
  }
  `)
  await sleep(1000)
  console.log(cat.say())
  dl6.end()
}

main().catch((error) => console.log(error))

Run:

$ node dl6ex.js
cat= {}
call D:\ccc\code\js\dl6\example\cat : say
meow
cat= { say: [Function: say] }
call D:\ccc\code\js\dl6\example\cat : say
hello

FAQs

Package last updated on 20 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts