This is the thing that npm uses to read package.\+json files. It validates some stuff, and loads some default things.

It keeps a cache of the files you\textquotesingle{}ve read, so that you don\textquotesingle{}t end up reading the same package.\+json file multiple times.

Note that if you just want to see what\textquotesingle{}s literally in the package.\+json file, you can usually do `var data = require(\textquotesingle{}some-\/module/package.\+json')\`{}.

This module is basically only needed by npm, but it\textquotesingle{}s handy to see what npm will see when it looks at your package.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23949}{}\doxysection{Usage}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23949}

\begin{DoxyCode}{0}
\DoxyCodeLine{var readJson = require('read-\/package-\/json')}
\DoxyCodeLine{}
\DoxyCodeLine{// readJson(filename, [logFunction=noop], [strict=false], cb)}
\DoxyCodeLine{readJson('/path/to/package.json', console.error, false, function (er, data) \{}
\DoxyCodeLine{  if (er) \{}
\DoxyCodeLine{    console.error("{}There was an error reading the file"{})}
\DoxyCodeLine{    return}
\DoxyCodeLine{  \}}
\DoxyCodeLine{}
\DoxyCodeLine{  console.error('the package data is', data)}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23950}{}\doxysection{read\+Json(file, \mbox{[}log\+Fn = noop\mbox{]}, \mbox{[}strict = false\mbox{]}, cb)}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23950}

\begin{DoxyItemize}
\item {\ttfamily file} \{String\} The path to the package.\+json file
\item {\ttfamily log\+Fn} \{Function\} Function to handle logging. Defaults to a noop.
\item {\ttfamily strict} \{Boolean\} True to enforce Sem\+Ver 2.\+0 version strings, and other strict requirements.
\item {\ttfamily cb} \{Function\} Gets called with {\ttfamily (er, data)}, as is The Node Way.
\end{DoxyItemize}

Reads the JSON file and does the things.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23951}{}\doxysection{$<$tt$>$package.\+json$<$/tt$>$ Fields}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23951}
See {\ttfamily man 5 package.\+json} or {\ttfamily npm help json}.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23952}{}\doxysection{read\+Json.\+log}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23952}
By default this is a reference to the {\ttfamily npmlog} module. But if that module can\textquotesingle{}t be found, then it\textquotesingle{}ll be set to just a dummy thing that does nothing.

Replace with your own {\ttfamily \{log,warn,error\}} object for fun loggy time.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23953}{}\doxysection{read\+Json.\+extras(file, data, cb)}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23953}
Run all the extra stuff relative to the file, with the parsed data.

Modifies the data as it does stuff. Calls the cb when it\textquotesingle{}s done.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23954}{}\doxysection{read\+Json.\+extra\+Set = \mbox{[}fn, fn, ...\mbox{]}}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23954}
Array of functions that are called by {\ttfamily extras}. Each one receives the arguments {\ttfamily fn(file, data, cb)} and is expected to call {\ttfamily cb(er, data)} when done or when an error occurs.

Order is indeterminate, so each function should be completely independent.

Mix and match!\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23955}{}\doxysection{Other Relevant Files Besides $<$tt$>$package.\+json$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23955}
Some other files have an effect on the resulting data object, in the following ways\+:\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23956}{}\doxysubsection{$<$tt$>$\+README?(.$\ast$)$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23956}
If there is a {\ttfamily README} or {\ttfamily README.$\ast$} file present, then npm will attach a {\ttfamily readme} field to the data with the contents of this file.

Owing to the fact that roughly 100\% of existing node modules have Markdown README files, it will generally be assumed to be Markdown, regardless of the extension. Please plan accordingly.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23957}{}\doxysubsection{$<$tt$>$server.\+js$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23957}
If there is a {\ttfamily server.\+js} file, and there is not already a {\ttfamily scripts.\+start} field, then {\ttfamily scripts.\+start} will be set to {\ttfamily node server.\+js}.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23958}{}\doxysubsection{$<$tt$>$\+AUTHORS$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23958}
If there is not already a {\ttfamily contributors} field, then the {\ttfamily contributors} field will be set to the contents of the {\ttfamily AUTHORS} file, split by lines, and parsed.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23959}{}\doxysubsection{$<$tt$>$bindings.\+gyp$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23959}
If a bindings.\+gyp file exists, and there is not already a {\ttfamily scripts.\+install} field, then the {\ttfamily scripts.\+install} field will be set to {\ttfamily node-\/gyp rebuild}.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23960}{}\doxysubsection{$<$tt$>$index.\+js$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23960}
If the json file does not exist, but there is a {\ttfamily index.\+js} file present instead, and that file has a package comment, then it will try to parse the package comment, and use that as the data instead.

A package comment looks like this\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{/**package}
\DoxyCodeLine{ * \{ "{}name"{}: "{}my-\/bare-\/module"{}}
\DoxyCodeLine{ * , "{}version"{}: "{}1.2.3"{}}
\DoxyCodeLine{ * , "{}description"{}: "{}etc...."{} \}}
\DoxyCodeLine{ **/}
\DoxyCodeLine{}
\DoxyCodeLine{// or...}
\DoxyCodeLine{}
\DoxyCodeLine{/**package}
\DoxyCodeLine{\{ "{}name"{}: "{}my-\/bare-\/module"{}}
\DoxyCodeLine{, "{}version"{}: "{}1.2.3"{}}
\DoxyCodeLine{, "{}description"{}: "{}etc...."{} \}}
\DoxyCodeLine{**/ }

\end{DoxyCode}


The important thing is that it starts with {\ttfamily /$\ast$$\ast$package}, and ends with {\ttfamily $\ast$$\ast$/}. If the package.\+json file exists, then the index.\+js is not parsed.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23961}{}\doxysubsection{$<$tt$>$\{directories.\+man\}/$\ast$.\mbox{[}0-\/9\mbox{]}$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23961}
If there is not already a {\ttfamily man} field defined as an array of files or a single file, and there is a {\ttfamily directories.\+man} field defined, then that directory will be searched for manpages.

Any valid manpages found in that directory will be assigned to the {\ttfamily man} array, and installed in the appropriate man directory at package install time, when installed globally on a Unix system.\hypertarget{md_sfcode_node_modules_read_package_json_README_autotoc_md23962}{}\doxysubsection{$<$tt$>$\{directories.\+bin\}/$\ast$$<$/tt$>$}\label{md_sfcode_node_modules_read_package_json_README_autotoc_md23962}
If there is not already a {\ttfamily bin} field defined as a string filename or a hash of {\ttfamily $<$name$>$ \+: $<$filename$>$} pairs, then the {\ttfamily directories.\+bin} directory will be searched and all the files within it will be linked as executables at install time.

When installing locally, npm links bins into {\ttfamily node\+\_\+modules/.bin}, which is in the {\ttfamily PATH} environ when npm runs scripts. When installing globally, they are linked into {\ttfamily \{prefix\}/bin}, which is presumably in the {\ttfamily PATH} environment variable. 