简体   繁体   English

命令“npm install fs”的问题

[英]Problem with the command "npm install fs"

I am not used to work with Linux, so maybe this is a silly question.我不习惯使用 Linux,所以也许这是一个愚蠢的问题。 In the lab that I am working on, I am asked to run the command "npm install fs" to read/write files.在我工作的实验室中,我被要求运行命令“npm install fs”来读/写文件。

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. PS:我在 Ubuntu 17.10 上工作。

在此处输入图片说明

fs is a module that doesn't have to be installed. fs是一个不必安装的模块。 It comes part of node.js core so you only need to require it in your code.它是 node.js 核心的一部分,所以你只需要在你的代码中要求它。

Instead of running npm install fs --save , just add the following line in the file you're wanting to use it in:无需运行npm install fs --save ,只需在要在其中使用它的文件中添加以下行:

const fs = require('fs');

Here are the docs: https://nodejs.dev/the-nodejs-fs-module以下是文档: 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您的项目中没有 package.json
  2. You are not in the correct directory when running npm install ... and therefore it cannot find your package.json.运行npm install ...时您不在正确的目录中,因此它找不到您的 package.json。

I believe your mistake is that you skipped the part where you initialize your npm repository (which generates your package.json).我相信您的错误是您跳过了初始化 npm 存储库(生成 package.json)的部分。

To initialize an npm repo, do the following:要初始化 npm 存储库,请执行以下操作:

  1. Navigate to your project root directory导航到您的项目根目录
  2. Run npm init and follow the instructions if when prompted.运行npm init并在出现提示时按照说明进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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