PSport PSport - 2 months ago 7x
Node.js Question

Copy CSS file content node js

I'm trying to copy the content of a CSS file using Node JS File system.
Here is my code :

var tpmFile = 'current.css';

var theme_file = FS.openSync("/tmp/"+tpmFile, "w");
var css_file = FS.readFileSync("/app/css/style1.css", "utf8");
FS.writeSync(theme_file, css_file);

is always empty, why? Folder's links are good.
Do I need to convert the css file?



probably the filename path is wrong, try to use __dirname or path module.

also i recommend using async reads and writes instead of sync (unless this code runs in the boot-time of the program).

var css_file;
fs.readFile(__dirname + '/app/css/style1.css', 'utf-8',function(err, data) {
  if (err) return console.log(err), false;
  css_file = data;

If you log the response for us for css_file, we can help you more.