
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
node-factorio-api
Advanced tools
Download and update mods from the Factorio Mod Portal
I recommend using yarn instead of npm, because it's (a lot) faster.
yarn add node-factorio-api (or npm install node-factorio-api)
import api from 'node-factorio-api'
// Initialize the api
api.init(false, 'path/to/mods/folder', 'path/to/saves/folder', '0.14.0')
// Set to true if you want to allow multiple version of a mod
// You must provide a username and a password or token
api.authenticate({
username: '',
token: '',
password: '',
require_ownership: false
}).then(token => {
// Search for mods that contain 'bob'
api.searchMods(
'bob'
).then((body) => {
// Download the found mods
api.downloadMods(body.results.map(x => {
return {name: x.name}
})).then(() => {
// Remove all mods that start with 'bob' (glob patterns)
api.removeModsMatching({name: "bob*"}).then(() => {
//Done
})
})
})
// Download Foreman version 1.0.0
api.downloadMod({name: 'Foreman', version: '1.0.0'}).then(() => {
// Download the latest version of Foreman
// This will remove all other installed foreman versions
api.downloadMod({name: 'Foreman'}).then(() => {
//Done
})
})
// Checks for updates and installs the latest version
// version is the version of the currently installed mod
api.updateMods([
{name: 'FARL', version: '0.0.1'},
{name :'blueprint-string', version: '4.0.0'}
]).then(() => {
// Download Foreman and Factorissimo2 after updating FARL and blueprint-string
api.downloadMods(['Foreman', 'Factorissimo2'].map(x => {return {name: x}})).then(() => {
// Done
})
// Does the same thing. The code above can be useful in some cases.
api.downloadMods([
{name: 'Foreman'},
{name :'Factorissimo2'}
]).then(() => {
api.removeMods([
{name: 'Foreman'},
{name :'Factorissimo2'},
{name :'FARL', version: '0.7.4'}
]).then(() => {
// Done
})
})
})
// Download all require dependencies
api.downloadDependencies({name: 'bobores'}, false).then(() => {
// Done
})
// Download all dependencies (including optional) from version 0.14.0
api.downloadDependencies(
{name: 'bobores', version: '0.14.0'}, true)
.then(() => {
// Done
})
// Get all the online games
api.getGames().then((body) => {
// Get details from the first game
api.getGameDetails(body[0].game_id).then((details) => {
// Download mods for the first game
// First remove base from the list
api.downloadMods(details.mods.filter(x => {
if (x.name == 'base')
return null
else
return x
})).then(() => {
//Downloaded mods for the first game
})
})
// Sort the array: most to least players online
let sortTop = body.sort((a, b) => {
let countA = 0
let countB = 0
if (b.players)
countB = b.players.length
if (a.players)
countA = a.players.length
return countB - countA
})
})
// Get all the mods used in a saved game
api.getModsFromSave('my_awesome_factory').then((mods) => {
// mods is an array of all mods in a save with name and version
})
api.getModsFromSaveFile('my_awesome_factory.zip').then((mods) => {
// mods is an array of all mods in a save with name and version
})
api.getModsFromSaves().then(list => {
// list is an array
/* Example output
[
{
name: "my_awesome_factory",
mods: [
{
name: "an_awesome_mod",
version: "1.2.3"
},
{
name: "another_awesome_mod",
version: "3.2.1"
}
]
},
{
name: "my_other_factory",
mods: [
{
name: "yet_another_mod",
version: "4.2.3"
},
{
name: "another_nice_mod",
version: "3.8.1"
}
]
}
]
*/
})
api.readModZip({name: "FARL", version: "0.7.4"}).then((info) => {
// info is the parsed info.json file of the mod
})
api.readModZipFile("FARL_0.7.4.zip").then((info) => {
// info is the parsed info.json file of the mod
})
api.readModZips().then((list) => {
// list is an array with the parsed info.json file of each mod
})
// Get the latest experimental version
api.getLatestGameVersion('experimental').then(version => {
// Download that version of the full client for Linux
// Please note that downloading the full client requires you to be
// logged in with either your password or with a session id
return api.downloadGame({version, build: 'alpha', distro: 'linux64'});
}).progress(value => {
// Log the percentage of the progress
console.log(Math.round(value * 100) + '%');
}).then(() => {
// It's done!
console.log("Done!");
}).catch(err => {
// Catch any potential errors
console.log(err);
});
}).catch(err => {
// Oops! Something went wrong
})
// You can call function outside the Promise of api.authenticate,
// but make sure that it's authenticated first
if (api.isAuthenticated()) {
api.downloadMod({name: 'Foreman'}).then(() => {
//Done
})
}
FAQs
Get data from the factorio mod portal and matchmaker
The npm package node-factorio-api receives a total of 15 weekly downloads. As such, node-factorio-api popularity was classified as not popular.
We found that node-factorio-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.