Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with the command "npm install fs"

I am not used to work with Linux, so maybe this is a silly question. In the lab that I am working on, I am asked to run the command "npm install fs" to read/write files.

But here is the error that i have and I don't know how to solve it, i couldn't find similar problems too.

PS: I am working on Ubuntu 17.10.

enter image description here

like image 486
Wassim Bouatay Avatar asked Sep 18 '25 15:09

Wassim Bouatay


1 Answers

fs is a module that doesn't have to be installed. It comes part of node.js core so you only need to require it in your code.

Instead of running npm install fs --save, just add the following line in the file you're wanting to use it in:

const fs = require('fs');

Here are the docs: https://nodejs.dev/the-nodejs-fs-module

However, to address your question, the error message your receiving is likely due to the fact that:

  1. You don't have a package.json in your project
  2. You are not in the correct directory when running npm install ... and therefore it cannot find your package.json.

I believe your mistake is that you skipped the part where you initialize your npm repository (which generates your package.json).

To initialize an npm repo, do the following:

  1. Navigate to your project root directory
  2. Run npm init and follow the instructions if when prompted.
like image 175
mwilson Avatar answered Sep 21 '25 03:09

mwilson