module.exports that include all functions in a single line

前端 未结 6 1016
小鲜肉
小鲜肉 2021-02-05 10:19

This is a follow-up question to In Node.js, how do I "include" functions from my other files?

I would like to include an external js file that contains common

6条回答
  •  名媛妹妹
    2021-02-05 11:09

    const fs = require("fs")
    
    
    var ExportAll = {
    
        deleteFile : function deleteFile(image,folder="uploads"){
        
            let imagePath = `public/${folder}/${image}`
        
            if (fs.existsSync(imagePath)){
                fs.unlinkSync(imagePath)
            }
        },
    
    
        checkFile : function checkFile(image,folder="uploads"){
        
            let imagePath = `public/${folder}/${image}`
        
            if (fs.existsSync(imagePath)){
                return true
            }
            else{
                return false
            }
        },
        
    
        rand : function(min=1,max=10) 
               {
            return Math.floor((Math.random() * max) + min)
              }
    }
    
    module.exports = ExportAll
     
    

提交回复
热议问题