Home > Back-end >  node js : where is the tmp folder
node js : where is the tmp folder

Time:06-30

I have a simple node project:

  • step 1 : I write a string to a file
  • step 2 : I read the file.

Everything works well, but I'm not able to find where is located the file generated at the first step even though I'm sure it has been generated as i'm able to read it in the second step.

code (./index.ts) :

import * as fs from "fs";

let data = "This is a file containing a collection of books generated";

fs.writeFile("/tmp/books.txt", data, (err) => {
  if (err) console.log(err);
  else {
    console.log("File written successfully\n");
    console.log("The written has the following contents:");
    console.log(fs.readFileSync("/tmp/books.txt", "utf8"));
  }
});

output (./package.json that contains the yarn start command) :

yarn start
yarn run v1.22.11
$ ts-node index.ts
File written successfully

The written has the following contents:
This is a file containing a collection of books generated

Thanks in advance for your help

CodePudding user response:

Accordance to fs.writeFile("/tmp/books.txt"..., it should be /tmp folder. It's from file system root, because path not like ./tmp (from current project folder).

Just check in terminal, your file should be here:

cd /tmp
ls
  • Related