2017-01-10 244 views
0

我试图启动一个需要node.js的新项目。创建文件夹后,我试图让node_modules显示在我的项目文件夹中。因此,我用在npm init之后package.json文件没有依赖关系

npm init 

,然后,我用

npm install 

的安装后,我意识到,我的node_modules文件夹为空,所以我检查了package.json。我意识到,没有依赖关系

有没有什么办法可以解决这个问题?

+0

NPM安装package_you_need --save-dev的。请参阅[doco](https://docs.npmjs.com/cli/install) – lloyd

+0

您尚未安装任何软件包,请尝试npm install express --save,您将在node_modules中看到express –

回答

1

当你做NPM初始化你可能输入的数值如下面的CLI中:

name: (testApp) 
Sorry, name can no longer contain capital letters. 
name: (testApp) testApp 
Sorry, name can no longer contain capital letters. 
name: (testApp) test-app 
version: (1.0.0) 
description: This is a test app 
entry point: (index.js) app.js 
test command: npm test 
git repository: 
keywords: 
author: Sagar Gopale 
license: (ISC) 
About to write to /home/sagargopale/Projects/testApp/package.json: 

;那么,的package.json创建了上面的配置如下:

{ 
    "name": "test-app", 
    "version": "1.0.0", 
    "description": "This is a test app", 
    "main": "app.js", 
    "scripts": { 
    "test": "npm test" 
    }, 
    "author": "Sagar Gopale", 
    "license": "ISC" 
} 

当你会安装任何依赖项,它会在package.json中添加依赖项块。例如,如果我这样做

npm install express --save 

那么的package.json看起来象下面这样:

{ 
    "name": "test-app", 
    "version": "1.0.0", 
    "description": "This is a test app", 
    "main": "app.js", 
    "scripts": { 
    "test": "npm test" 
    }, 
    "author": "Sagar Gopale", 
    "license": "ISC", 
    "dependencies": { 
    "express": "^4.14.0" 
    } 
} 
相关问题