Reputation: 4026
So i start off with writing my own node.js app and the only thing i want is to include a package for saml.
So i was wondering what is the minimal requirement for my app.
I was just creating a node.js file and then i installed the package by:
node install some-saml-passports-package
.
I got this warning after installation:
npm WARN enoent ENOENT: no such file or directory, open '.../mynodeapp/package.json'
I removed the package and created a package.json
file. Which results in a parsing error because there was no content inside.
I have read that I only need a package.json
when I plan to create my own package. Also I read something about local and global installation of package files in npm. Well, i need a bit of clarification for my doing.
What is the use of package.json
?
Do I need it when I only want to create a standalone app in node with one dependency to an existing package?
Is it recommended even if I don't need it at all?
Upvotes: 8
Views: 4902
Reputation: 39273
The minimal file is:
{
}
Now you can start using commands like npm install web3 --save
and they will save onto this file.
Upvotes: 3
Reputation: 2023
There is no minimum requirement for node.js application. The package.json
is only required to manage your application for dependencies, module descriptions , handle npm scripts etc. You can install packages without package.json
, just don't use the --save
flag with npm install
. E.g.:
npm install <package_name>
- you can still run your node application without any problem. But I will suggest you to add a package.json
file and add following:
{
"name": "<package_name>",
"version": "<version>", //0.0.1 for starters
"description": "",
"main": "<entry point of application>", // example: app.js , index.js etc
,
"author": "<your name>",
"license": "ISC",
"dependencies": {}
}
You can create this by adding it manually or just execute npm init
in your project root directory and answer some basic questions in console.
Here are some useful links:
Upvotes: 7
Reputation: 908
Create package.json via npm init
command.
Package.json contains data about your project and what is more important for standalone app - it contains dependencies list. You can install all dependencies from package.json with npm install
.
If you want to install package and save it in package.json type npm install package-name --save
.
Upvotes: 2