创建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

然后又报出新的错误

> myapp@0.0.0 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! myapp@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myapp@0.0.0 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

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值