Read Package.json file from Node.JS module

Emmanuel Gautier / May 22, 2023

1 min read

When you write a program you may want to read the content of the package.json file like what is the current package version. Here is one very simple way to read the content of this file.

With Node.JS module, is very simple to import the content of a JSON and package.json is no more than a JSON file so the simple code below works fine:

example.mjs
import packageJSON from './package.json' assert { type: 'json' };

console.log(packageJSON.version);
// Output: 1.0.0

Consulting

If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.

Share this post
Follow the RSS feed

Subscribe to the newsletter

Get the latest news about tech new articles and projects.