Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js minimal setup and for what is the package.json?

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?

like image 266
Gobliins Avatar asked Nov 14 '16 10:11

Gobliins


People also ask

What is the use of package json in node JS?

The package. json file is the heart of any Node project. It records important metadata about a project which is required before publishing to NPM, and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to our package.

What is package json What is it used for?

A package. json is a JSON file that exists at the root of a Javascript/Node project. It holds metadata relevant to the project and it is used for managing the project's dependencies, scripts, version and a whole lot more.

What are the bare minimum fields required in package json?

Required name and version fields A package. json file must contain "name" and "version" fields. The "name" field contains your package's name, and must be lowercase and one word, and may contain hyphens and underscores. The "version" field must be in the form x.x.x and follow the semantic versioning guidelines.

What is npm package json?

All npm packages contain a file, usually in the project root, called package. json - this file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies.


2 Answers

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:

npm init

how to use package.json

like image 69
AJS Avatar answered Oct 03 '22 06:10

AJS


The minimal file is:

{
}

Now you can start using commands like npm install web3 --save and they will save onto this file.

like image 27
William Entriken Avatar answered Oct 03 '22 05:10

William Entriken