Parse Path - Node.js File

Node.js examples for File:Path

Description

Parse Path

Demo Code

function parsePaths(str) {
    var result = [];
    if (!str) {/*from  w w  w. java 2s  .c o  m*/
        return result;
    }

    if (fs.exists(str)) {
        fs.read(str)
            .split('\n')
            .forEach(function(line) {
                if (line !== '') {
                    result.push(line);
                }
            });
    } else {
        str.split(',').forEach(function(item) {
            result.push(trim(item));
        });
    }
    return result;
}

Related Tutorials