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!
DISCUSSION
Classic DEV Post from Jun 9

How do you gain a deep understanding of your code?

Discussion on how to learn with the goal of knowing the language/framework inside out.

READ POST
Follow @lynnewritescode 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
Haskell for javascript programmers.
#haskell #javascript #functional
How to start contributing to open source as a junior or newbie?
#discuss #beginners
Top 26 JavaScript Interview Questions I Wish I Knew
#javascript #interview #fullstack #career
Lessons I learned from training with special forces that I use in software development
#beginners #career #motivation #dieliving
What and How to Test with Jest and Enzyme. Full Instruction on React Components Testing
#frontend #react #javascript #jest
ES6 Destructuring with Crayons
#es6 #javascript
The Stack : Making a free open-source disposable email service prototype (inboxkitten.com) in 14 hours
#opensource #serverless #javascript #vue
Introducing Learn Code from Us
#showdev #beginners #leadership