Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
init-package-json
Advanced tools
The init-package-json npm package is a utility that helps in creating a package.json file for a Node.js project. It guides users through a series of prompts to gather necessary information and then generates a package.json file based on the provided inputs.
Interactive Package Initialization
This feature allows users to initialize a package.json file interactively. The script prompts the user for various details like package name, version, description, etc., and then generates the package.json file.
const init = require('init-package-json');
const path = process.cwd();
const initFile = path.resolve(process.env.HOME, '.npm-init');
init(path, initFile, {}, (err, data) => {
if (err) {
console.error(err);
} else {
console.log('Package initialized:', data);
}
});
Custom Prompts
This feature allows users to provide custom configuration data for the package.json file. Instead of going through the interactive prompts, users can supply predefined values.
const init = require('init-package-json');
const path = process.cwd();
const initFile = path.resolve(process.env.HOME, '.npm-init');
const configData = {
'name': 'my-custom-package',
'version': '1.0.0',
'description': 'A custom package'
};
init(path, initFile, configData, (err, data) => {
if (err) {
console.error(err);
} else {
console.log('Custom package initialized:', data);
}
});
Yeoman Generator is a scaffolding tool that helps in generating complete projects, including package.json files. It offers more extensive functionality compared to init-package-json, such as generating boilerplate code, setting up project structure, and more.
The create-package-json package is a simpler alternative to init-package-json. It focuses solely on generating a package.json file with minimal prompts and configuration options. It is less interactive but quicker for straightforward setups.
npm-init is a built-in npm command that initializes a package.json file. It is similar to init-package-json but is more tightly integrated with npm itself. It offers a basic set of prompts and configurations.
A node module to get your node module started.
const init = require('init-package-json')
const path = require('path')
// a path to a promzard module. In the event that this file is
// not found, one will be provided for you.
const initFile = path.resolve(process.env.HOME, '.npm-init')
// the dir where we're doin stuff.
const dir = process.cwd()
// extra stuff that gets put into the PromZard module's context.
// In npm, this is the resolved config object. Exposed as 'config'
// Optional.
const configData = { some: 'extra stuff' }
// Any existing stuff from the package.json file is also exposed in the
// PromZard module as the `package` object. There will also be three
// vars for:
// * `filename` path to the package.json file
// * `basename` the tip of the package dir
// * `dirname` the parent of the package dir
const data = await init(dir, initFile, configData)
// the data's already been written to {dir}/package.json
// now you can do stuff with it
See PromZard for details about what can go in the config file.
FAQs
A node module to get your node module started
The npm package init-package-json receives a total of 1,324,056 weekly downloads. As such, init-package-json popularity was classified as popular.
We found that init-package-json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.