How read data file from gulp.src('json/username.json')
in node_modules ( node_modules / gulp-up / index.js )?
username.json
{
"name": "Rikardo",
"city": "Mosscov",
"age": "18"
}
gulpfile.js
upmodul = require("gulp-up");
gulp.task('gulp-ren', function () {
return gulp.src('json/username.json')
.pipe(myfunction());
});
gulp.task('ge', ['gulp-ren']);
node_modules / gulp-up / index.js
'use strict';
var Stream = require('stream');
function loger() {
//The needed maybe not Transform and Read file
var stream = new Stream.Transform({ objectMode: true });
stream._transform = function (file, unused, callback) {
console.log('test !!! - ' + file.contents);
return stream;
}
}
module.exports = loger;
I write in console command: gulp ge
, and give error:
[00:19:39] TypeError: Cannot read property 'on' of undefined
at DestroyableTransform.Readable.pipe (E:\Developers\WebDeveloper\OpenServer
-WebProg\domains\progectapi2\node_modules\vinyl-fs\node_modules\readable-stream\
lib\_stream_readable.js:516:7)
at Gulp.<anonymous> (E:\Developers\WebDeveloper\OpenServer-WebProg\domains\p
rogectapi2\gulpfile.js:159:9)
at module.exports (E:\Developers\WebDeveloper\OpenServer-WebProg\domains\pro
gectapi2\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (E:\Developers\WebDeveloper\OpenServer-WebProg
\domains\progectapi2\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (E:\Developers\WebDeveloper\OpenServer-WebProg
\domains\progectapi2\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (E:\Developers\WebDeveloper\OpenServer-WebProg\do
mains\progectapi2\node_modules\orchestrator\index.js:134:8)
at C:\Users\Tiki
\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at nextTickCallbackWith0Args (node.js:433:9)
at process._tickCallback (node.js:362:13)
at Function.Module.runMain (module.js:432:11)
I don't really understand your question... but if you want to read the json/username.json
file, then you can just require it, like so:
var json = require('json/username.json');
The json variable will contain the data from the username.json file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.