创建express项目及npm start报错解决办法

express的安装这里简要的说一下

cnpm install express -g
cnpm install -g express-generator

分别安装好express及其命令工具
切换到想要安装的项目路径,建立myapp项目

express myapp

接下来输入

npm start

这个时候博主就报错了

npm ERR! path F:\CODE\Node.js\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'F:\CODE\Node.js\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\SoftWare\Node.js_10.15.3\node_cache\_logs\2019-04-07T02_00_12_770Z-debug.log

期间还有报以下的错

npm ERR! missing script: start

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\SoftWare\Node.js_10.15.3\node_cache\_logs\2019-04-07T02_04_30_838Z-debug.log

按照这里的报错,查了很多网上的方法都解决不了,后来发现是博主的没有进入到刚刚建好的项目文件夹。于是

cd myapp
npm start

然后又报出新的错误

> [email protected] start F:\CODE\Node.js\myapp
> node ./bin/www

internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module 'http-errors'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (F:\CODE\Node.js\myapp\app.js:1:81)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\SoftWare\Node.js_10.15.3\node_cache\_logs\2019-04-07T02_16_26_677Z-debug.log

最后终于找到了方法

cd myapp && npm install

或者

cd myapp
npm intall    //这里cnpm也可以

进入项目目录并安装所有依赖(用cnpm install也可以),然后

npm start

浏览器中访问localhost:3000,就可以显示如下的内容了
在这里插入图片描述
最后附上vs code调试node.js的链接,学习记录用
https://cnodejs.org/topic/58f376fec749f63d48fe9548

发布了18 篇原创文章 · 获赞 2 · 访问量 5138

猜你喜欢

转载自blog.csdn.net/qq_39672732/article/details/89069276