简体   繁体   中英

Create a serverside file in Meteor

I was wondering how to write files in Meteor to the server. I was looking at this NodeJS code, but it wasn't working when I tried it in the server javascript code.

    var fs = require('fs');
    fs.writeFile("/client/test", "Hey there!", function(err) {
    if(err)
        console.log(err);
    else
        console.log("The file was saved!");
    }); 

It was saying that require wasn't defined. Anyways, does anybody know how to write files to the server in Meteor?

You need to use Npm.require instead of just require .

var fs = Npm.require('fs');

This will work for any module that is part of node or meteor (such as fs so its not a problem here). However, for other npm modules you would have to use Meteor NPM or write your own smart package

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM