Erik Waters Erik Waters - 1 year ago 117
Node.js Question

Node / statSync issues

I'm trying to log an array of numerically named sub-directories in "e:\subdirectory\" by using fs.statSynch but I keep getting the error "module.exports" is not a function; to my understanding, this is exactly how I'm supposed to export the data

I'm using the synchronous version because I want the array to finish populating before it's exported.

this is for a "proof of concept", I plan on serving an html doc and pushing this array to an input field

here is the code...


var fs = require('fs');

function checkE() {
for (var i = 1, accts = [], path = "e:\\subdirectory\\"; i <10000; i++ ) {
var target = fs.statSynch(path + i.toString())
if (target.isDirectory()) { accts.push(i) }



var checke = require('./checke.js')


Answer Source

You need to assign something to module.exports not call it like a function. module.exports is an object


var fs = require('fs');

module.exports = {
    checkE: function checkE() {
       var accts = [];
       var path = 'e:\\subdirectory\\';

       for (var i = 1; i <10000; i++ ) {
           var target = fs.statSync(path + i.toString())
           if (target.isDirectory())

       return accts;


var checke = require('./checke.js');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download