Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serkanyersen/pjson
Let's you read package.json from any directory
https://github.com/serkanyersen/pjson
helpers json-files nodejs npm package-json typescript utilities
Last synced: about 2 months ago
JSON representation
Let's you read package.json from any directory
- Host: GitHub
- URL: https://github.com/serkanyersen/pjson
- Owner: serkanyersen
- License: mit
- Created: 2015-07-06T01:48:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-29T20:25:35.000Z (over 6 years ago)
- Last Synced: 2024-09-27T15:04:14.291Z (3 months ago)
- Topics: helpers, json-files, nodejs, npm, package-json, typescript, utilities
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 25
- Watchers: 4
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PJSON
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fserkanyersen%2Fpjson.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fserkanyersen%2Fpjson?ref=badge_shield)PJSON is a simple npm package that lets you read the package.json file.
## Usage
Install it
```
npm install pjson --save
```and use it in your code like this
```javascript
var pjson = require('pjson');// simply access values package.json
console.log(pjson.version);
```## Why?
In Node.js you can already import json files by simple giving their names in the `require` statements but this approach doesn't always work well.
First of all it's path dependent. So if your project has a nested structure you might end up with code that looks like this
```javascript
var pjson = require('../../../package.json');
```#### TypeScript
In typescript you cannot create module definitions for relatively imported things. PJSON resolves this issue for you because you can import it just by name
#### Old versions of Node
Importing JSON files using require is only enabled in later versions of node. For old versions, PJSON might be useful
#### Because I need it
It's simple, I needed it for my own project and I though it might be useful for others as well :)
## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fserkanyersen%2Fpjson.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fserkanyersen%2Fpjson?ref=badge_large)