Name: node-screeps-api
Owner: screepers
Description: Node.js API For screeps
Created: 2016-07-29 20:04:47.0
Updated: 2018-02-02 02:17:29.0
Pushed: 2018-01-08 16:50:53.0
Homepage: null
Size: 256
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
As of 12/29/2017 Screeps now uses auth tokens obtained via your screeps account settings. User/pass auth will stop working February 1, 2018! Screeps Announcement
As of 1.0, all functions return Promises
t { ScreepsAPI } = require('screeps-api');
t fs = require('fs');
ll options are optional
t api = new ScreepsAPI({
ken: 'Your Token from Account/Auth Tokens'
otocol: 'https',
stname: 'screeps.com',
rt: 443,
th: '/' // Do no include '/api', it will be added automatically
ou can overwrite parameters if needed
auth('screeps@email.com','notMyPass',{
otocol: 'https',
stname: 'screeps.com',
rt: 443,
th: '/' // Do no include '/api', it will be added automatically
f you want to point to the screeps PTR (Public Test Realm),
ou can set the 'path' option to '/ptr' and it will work fine.
ump Memory
memory.get()
hen(memory => {
fs.writeFileSync('memory.json', JSON.stringify(memory))
atch(err => console.error(err));
ump Memory Path
memory.get('rooms.W0N0')
hen(memory => {
fs.writeFileSync('memory.rooms.W0N0.json', JSON.stringify(memory))
atch(err => console.error(err));
et user info
me().then((user)=>console.log(user))
ocket API
socket.connect()
vents have the structure of:
channel: 'room',
id: 'E3N3', // Only on certain events
data: { ... }
socket.on('connected',()=>{
// Do stuff after conntected
socket.on('auth',(event)=>{
event.data.status contains either 'ok' or 'failed'
// Do stuff after auth
vents: (Not a complete list)
onnected disconnected message auth time protocol package subscribe unsubscribe console
ubscribtions can be queued even before the socket connects or auths,
lthough you may want to subscribe from the connected or auth callback to better handle reconnects
socket.subscribe('console')
socket.on('console',(event)=>{
event.data.messages.log // List of console.log output for tick
tarting in 1.0, you can also pass a handler straight to subscribe!
socket.subscribe('console', (event)=>{
event.data.messages.log // List of console.log output for tick
ore common examples
socket.subscribe('cpu',(event)=>console.log('cpu',event.data))
code.get('default').then(data=>console.log('code',data))
code.set('default',{
main: 'module.exports.loop = function(){ ... }'
socket.subscribe('memory/stats',(event)=>{
console.log('stats',event.data)
socket.subscribe('memory/rooms.E0N0',(event)=>{
console.log('E0N0 Memory',event.data)
Server endpoints are listed in the docs
folder: