{"id":21059096,"url":"https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo","last_synced_at":"2026-04-25T22:31:55.021Z","repository":{"id":110982005,"uuid":"167654374","full_name":"ganeshrvel/tutorial-electron-nodejs-import-packageinfo","owner":"ganeshrvel","description":"Import values from package.json into electron/nodejs application.","archived":false,"fork":false,"pushed_at":"2019-01-26T06:46:35.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-09T06:49:57.624Z","etag":null,"topics":["electron","nodejs","packageinfo"],"latest_commit_sha":null,"homepage":"https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ganeshrvel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-26T05:41:18.000Z","updated_at":"2019-01-26T06:46:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"9410bd26-e15b-462d-98b2-be28ebb6c242","html_url":"https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ganeshrvel/tutorial-electron-nodejs-import-packageinfo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ganeshrvel","download_url":"https://codeload.github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32279652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electron","nodejs","packageinfo"],"created_at":"2024-11-19T17:09:54.802Z","updated_at":"2026-04-25T22:31:54.985Z","avatar_url":"https://github.com/ganeshrvel.png","language":null,"funding_links":["https://paypal.me/ganeshrvel"],"categories":[],"sub_categories":[],"readme":"# Import values from package.json into electron/nodejs application.\n\n- Author: [Ganesh Rathinavel](https://www.linkedin.com/in/ganeshrvel \"Ganesh Rathinavel\")\n- License: [MIT](https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo/blob/master/LICENSE \"MIT\")\n- Website URL: [https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo](https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo/ \"https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo\")\n- Repo URL: [https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo](https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo/ \"https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo\")\n- Contacts: ganeshrvel@outlook.com\n\n\n### Introduction\n\n##### I have seen many users importing 'package.json' directly into the node.js project. This is a programming disaster as it could leak your sensitive information such as \"scripts\" or private TOKENS into the bundled js files.\n##### There is no single clearcut solution to get this done inside an electron app. It has to be handled intelligently using algorithms and fallbacks.\n##### I have spent a significant amount of time researching how to get this done. This was originally implemented inside [OpenMTP - Advanced Android File Transfer Application for macOS](https://github.com/ganeshrvel/openmtp \"OpenMTP - Advanced Android File Transfer Application for macOS\").\n\n### Implementation\n\n- Install npm packages\n\n```shell\n$ npm install electron-root-path\n\nor \n\n$ yarn add electron-root-path\n```\n\n- Add the below code inside your *webpack.config.js* file (for both production and development)\n\n```javascript\nimport { rootPath } from 'electron-root-path';\n\nconst pkg = require(join(rootPath, 'package.json'));\n\nplugins: [\n    new webpack.DefinePlugin({\n      PKG_INFO: {\n        productName: JSON.stringify(pkg.productName),\n        description: JSON.stringify(pkg.description),\n        name: JSON.stringify(pkg.name),\n        author: JSON.stringify(pkg.author),\n        version: JSON.stringify(pkg.version),\n        repository: JSON.stringify(pkg.repository),\n        homepage: JSON.stringify(pkg.homepage)\n      }\n    }),\n  ]\n```\n\n- Create a file *./app/pkginfo.js* and add the below code\n\n```javascript\n'use strict';\n\nimport { join } from 'path';\nimport { readFileSync } from 'fs';\nimport { rootPath } from 'electron-root-path';\n\nlet _pkginfo = {};\n\n// eslint-disable-next-line no-undef\nif (typeof PKG_INFO !== 'undefined' \u0026\u0026 PKG_INFO !== null) {\n  // eslint-disable-next-line no-undef\n  _pkginfo = PKG_INFO;\n} else {\n  /* This is a fallback incase the webpack DefinePlugin modules hasn't been initialized yet. */\n  /* Developement mode only */\n  _pkginfo = JSON.parse(\n    readFileSync(join(rootPath, 'package.json'), { encoding: 'utf8' })\n  );\n}\n\nexport const pkginfo = _pkginfo;\n```\n\n\n### Clone\n```shell\n$ git clone --depth 1 --single-branch --branch master https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo.git\n\n$ cd tutorial-electron-nodejs-import-packageinfo\n```\n\n### Contribute\n- Fork the repo and create your branch from master.\n- Ensure that the changes pass linting.\n- Update the documentation if needed.\n- Make sure your code lints.\n- Issue a pull request!\n\nWhen you submit code changes, your submissions are understood to be under the same [MIT License](https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo/blob/master/LICENSE \"MIT License\") that covers the project. Feel free to contact the maintainers if that's a concern.\n\n\n### Buy me a coffee\nHelp me keep the app FREE and open for all.\nPaypal me: [paypal.me/ganeshrvel](https://paypal.me/ganeshrvel \"paypal.me/ganeshrvel\")\n\n### Contacts\nPlease feel free to contact me at ganeshrvel@outlook.com\n\n### More repos\n- [OpenMTP  - Advanced Android File Transfer Application for macOS](https://github.com/ganeshrvel/openmtp \"OpenMTP  - Advanced Android File Transfer Application for macOS\")\n- [Tutorial Series by Ganesh Rathinavel](https://github.com/ganeshrvel/tutorial-series-ganesh-rathinavel \"Tutorial Series by Ganesh Rathinavel\")\n- [npm: electron-root-path](https://github.com/ganeshrvel/npm-electron-root-path \"Get the root path of an Electron Application\")\n- [Electron React Redux Advanced Boilerplate](https://github.com/ganeshrvel/electron-react-redux-advanced-boilerplate \"Electron React Redux Advanced Boilerplate\")\n\n### License\ntutorial-electron-nodejs-import-packageinfo is released under [MIT License](https://github.com/ganeshrvel/tutorial-electron-nodejs-import-packageinfo/blob/master/LICENSE \"MIT License\").\n\nCopyright © 2018-Present Ganesh Rathinavel\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganeshrvel%2Ftutorial-electron-nodejs-import-packageinfo/lists"}