diff --git a/src/app.js b/src/app.js index 4a24c3e..8c13c2a 100644 --- a/src/app.js +++ b/src/app.js @@ -8,9 +8,6 @@ var indexRouter = require('./routes/index'); var app = express(); -// Declare a global variable to hold project path -global.__basedir = __dirname; - // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); diff --git a/src/config/constants.js b/src/config/constants.js new file mode 100644 index 0000000..be33c9b --- /dev/null +++ b/src/config/constants.js @@ -0,0 +1,3 @@ +module.exports = { + basedir: __dirname, +}; \ No newline at end of file diff --git a/src/models/file.js b/src/models/file.js index 1eb911e..e775916 100644 --- a/src/models/file.js +++ b/src/models/file.js @@ -1,3 +1,4 @@ +/* global basedir */ const path = require('path'); const URL = require("url"); const fs = require('fs'); @@ -12,7 +13,10 @@ const { PassThrough } = require('stream'); const slugify = require('slugify'); const e = require('express'); -const dest = path.join(appRoot, 'public/csv'); +// Load project path from config/constants.js +const { basedir } = require('../config/constants'); + +const dest = path.join(basedir, 'public/csv'); // Create a generateFilePath function witch returns a path with a filename and datetime @@ -116,12 +120,13 @@ class File extends EventEmitter { // create a parse method which read the file and return a stream - async parse(columns) { + parse(columns) { const stream = new PassThrough(); // check if columns is valid if (!columns || columns.length) { - return Promise.reject(new Error('Invalid columns')); + // return Promise.reject(new Error('Invalid columns')); + return false; } // Create a variable to hold csv columns indexes