Get dependencies written in package.json from JavaScript code

This is just a memo about how to refer dependencies written in package.json from JavaScript code.

import pkg from './package.json';

const dependencies = Object.keys(pkg.dependencies);
const devDependencies = Object.keys(pkg.devDependencies);
const peerDependencies = Object.keys(pkg.peerDependencies);

It would be useful in case of specifying externals in rollup.config.js.

{
  external: Object.keys(pkg.dependencies)
  ...
}
Did you find this post useful? Show some love!
Classic DEV Post from Dec 19 '17

What are your must-read tech books for 2018?

Hey there! Though New Year’s resolutions have never played an important role ...

READ POST
Follow @bekka to see more of their posts in your feed.
Masato Ohba
Software Engineer
More from @ohbarye
How to find Good First Issues to Contribute OSS
#opensource #showdev #javascript #graphql
Pixelate characters with canvas, and draw generative art!
#showdev #javascript #typescript #npm
Trending on dev.to
Friday Frontend: Ultimate Guide to Learning CSS Edition
#fridayfrontend #css #javascript
Memoization in a Nutshell
#explainlikeimfive #beginners #javascript
Master the World of ReactJS - Issue #12
#react #redux #typescript #javascript
Angular SEO Done Right with Server-Side Rendering [Live Demo]
#javascript #webdev #showdev #angular
The Shell Introduction I Wish I Had
#shell #productivity #beginners #bash
Securing your Node js api with JSON Web Token
#javascript #node #jwt
What Do You Look For in a Mentor?
#javascript #discuss #frontend #mentorship
How to use PHPUnit for Laravel
#php #laravel #phpunit #beginners