ProtoTyPus
ProtoTyPus

Reputation: 1324

NodeJS package.json


I'm setting NodeJS but when I run "connect", it says me that there is not "package.json".
I've installed NodeJS ->

$ npm install -g express-generator
$ npm install express
$ npm install connect
$ npm install serve-static
$ node server.js

But it doesnt work. In every "install" trying says that it doesn't find the package.json.

Configuration:
Windows: 10
NodeJS: 6.5.0

Thank you!

Upvotes: 2

Views: 2507

Answers (6)

Rupesh
Rupesh

Reputation: 1

run npm init command on your command prompt to create a project, it will automatically create a package.json file once package.json file is created you can install other dependencies

ex:

npm install --save express

npm install --save restify

Upvotes: 0

Gousia
Gousia

Reputation: 63

First create a package.json file. You can either create it using npm init command or by creating a file manually as package.json in the particular path for ex if your node modules is on desktop then /home/Desktop/node_modules/connect. In the package.json file give the required details as in below format. For ex,

{
  "name": "connect",
  "version": "1.0.0",
  "dependencies": {
    "express": "^1.0.0"
  },
  "devDependencies" : {
    "underscore": "^3.1.0"
  }
}

If you want to create package.json using npm init then at the command prompt it will ask for the details to be stored in package.json file by filling the respective values and pressing enter, package.json will be created. After that the you can install the module you want.

Upvotes: 0

Krishna Mohan
Krishna Mohan

Reputation: 169

$ npm -g install express-generator
$ express (package_name)
$ npm install

These commands create a folder with the package_name in the current directory and install the required node modules with package.json

Upvotes: 2

Morris
Morris

Reputation: 601

For create a package.json, write the follow command into Dos: npm init for create step by step each parameter. Install the packages with parameter --save for annotate the package into package.json. for example : npm install express --save

Upvotes: 0

alex
alex

Reputation: 5573

First create a package.json (here using the default values by including -y) and then install the dependencies while saving them into the package.json using -S.

$ npm init -y
$ npm install -g express-generator
$ npm install express -S
$ npm install connect -S
$ npm install serve-static -S
$ node server.js

Note that you can leave out the installation of express-generator as it should already be installed globally.

Documentation on npm init.

Upvotes: 2

AndreaM16
AndreaM16

Reputation: 3975

You need to create a file named package.json in your main directory like the following

{
  "name": "yourAppName",
  "main": "server.js",
  "dependencies": {
    "body-parser": "~1.5.2",
    "express": "~4.7.2",
     . . .
  }
}

That is just an example package.json. You can specify all the modules and version that you want to install trough npm install.

You get an error because your package.json does not exist. If you create it and re-run your command it will add your modules to it.

Hope I've been helpful.

Upvotes: 1

Related Questions