简体   繁体   English

运行 Express.js 时 Node.js Package.json 文件错误

[英]Node.js Package.json file error while running Express.js

I am new to using Node.js我是使用 Node.js 的新手

I have a project folder structure C:\A\B\C\我有一个项目文件夹结构C:\A\B\C\

I have C:\A\B\C\html_pages\index.html in which I have React.js code having CDN我有C:\A\B\C\html_pages\index.html其中我有 React.js 代码具有 CDN

and C:\A\B\C\server.js which has Express.js code which I want to run.C:\A\B\C\server.js有我想要运行的 Express.js 代码。

  1. I installed nvm then installed Node.js using command nvm install 4.5我安装了 nvm 然后使用命令nvm install 4.5安装了 Node.js

  2. In windows PowerShell, I went to project directory C:\A\B\C and used npm init (node_modules were not created in this step) In windows PowerShell, I went to project directory C:\A\B\C and used npm init (node_modules were not created in this step)

  3. Did npm install express --save to use the express module (now node_modules folder was created but package.json was inside express folder) npm install express --save是否使用 express 模块(现在 node_modules 文件夹已创建,但 package.json 在 express 文件夹内)

  4. Used npm start to start the web server but it gave following error.使用npm start启动 web 服务器,但它给出了以下错误。

ENOENT: no such file or directory, open 'C:\A\B\C\package.json' I checked the posts on Stackoverflow for this error but was not able to solve it. ENOENT: no such file or directory, open 'C:\A\B\C\package.json'我检查了 Stackoverflow 上的帖子是否存在此错误,但无法解决。 Should the package.json be generated directly under 'C:\A\B\C\ ? package.json 应该直接在'C:\A\B\C\下生成吗? I have installed Node.js in C:\Program Files\nodejs while project is not under Program Files, is this related to this?我在C:\Program Files\nodejs中安装了 Node.js,而项目不在 Program Files 下,这与此有关吗?

PS : Used npm init --yes so that it installs node_modules inside my project folder and got the request processed but port 3000 gives error that it did not get GET request PS:使用 npm init --yes 以便它在我的项目文件夹中安装 node_modules 并处理请求,但端口 3000 给出错误,它没有收到 GET 请求

The package.json file should be on the root of your directory. package.json文件应位于目录的根目录中。 Open command line from your root directory and type,从根目录打开命令行并键入,

npm init

This will generate a package.json file on that directory.这将在该目录上生成 package.json 文件。

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

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