刚接触nodejs和npm,按照教程需要npm引入模块,
(教程:http://blog.csdn.net/binyao02...)
执行npm install formidable,遂报错
no such file or directory
No description,
No repo-field,
No README-data,
No license-field
然后我改由执行 npm install (之前了解到的是这个命令更新npm的包(不知道是不是?))
但npm install报了同样的错误。截图如下:(SF上传图片的功能挂了)
C:\Users\fanzm1\workspace\Astone\0115_NodeJS>npm install formidable
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\fanzm1\workspace\Astone\0115_NodeJS\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\fanzm1\workspace\Astone\0115_NodeJS\package.json'
npm WARN 0115_NodeJS No description
npm WARN 0115_NodeJS No repository field.
npm WARN 0115_NodeJS No README data
npm WARN 0115_NodeJS No license field.
+ formidable@1.1.1
added 1 package in 1.475s
C:\Users\fanzm1\workspace\Astone\0115_NodeJS>npm install
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\fanzm1\workspace\Astone\0115_NodeJS\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\fanzm1\workspace\Astone\0115_NodeJS\package.json'
npm WARN 0115_NodeJS No description
npm WARN 0115_NodeJS No repository field.
npm WARN 0115_NodeJS No README data
npm WARN 0115_NodeJS No license field.
up to date in 0.116s
提问:
① 如何才能正确安装npm模块?
① 如何正确使用npm install?(是不是一定要在npm的安装目录下使用?(好像不是...))
② 是否需要有一个package.json(之前同学告诉我如果目录下面没有“package.json”,npm将无法安装)?
③ 如果是,如何生成 package.json?
出错原因
看这句提示,是因为缺少
package.json
这个文件。解决方法:
首先,初始化项目,一路回车就行
接着安装依赖