npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cloud-core-server

v2.0.23

Published

An open-source way to run Minecraft easily on linux using JavaScript.

Downloads

9

Readme


Cloud Core is a highly configurable Minecraft Java wrapper, it uses child_process, express, websocket and many other modules to expose your Minecraft Java server to the web.

  • HTTP Api for sending commands, requesting the last 100 lines of console and getting the server usage statistics (cpu & ram).
  • Websocket support to receive console lines, send commands and start / stop the server.
  • A fully automated backup system that backs up your whole server on a bi-weekly / bi-monthly basis.
  • Highly customizable with events, and functions to interact with the server from plain javascript.
  • Highly secured, only letting users with a certain password connect.
  • Logs every command sent into the Minecraft latest log with an optional user field to log a command by a user.

Install

Firstly make sure you have the following dependencies:

  • Java 8 or above.
  • NodeJS 12 or above.
  • Access to SSH on your host.

Install via NPM...

npm install cloud-core-server

To start a server, you need to create a javascript file in the root of your server.

Include Cloud Core into this script by entering this line:

const CloudCore = require("cloud-core-server");

Then make a new instance of CloudCore:

const server = new CloudCore(options);

You need to configure most of the options, download the example-start.js file to see an example of what you might find, all options and default values are listed here:

core:

core.backups:

remote:

Running

Start your server by installing pm2 and running this command:

pm2 start (your start javascript file) -n (server name)

Your server will now be started. You can use pm2 log (server name) to view the server log or if there are any errors.

Be careful when you are stopping your server. If you stop your server via pm2 stop (server name) your server can be shut down incorrectly. Please first stop your server through the web, then stop it via pm2.

You can also start multiple servers using pm2.

Accessing

HTTP GET request to any URL to get the last 100 lines of the console.

HTTP POST request to any URL to send a command.

Open websocket to any URL.

Start & stop.

Make sure you follow authentication rules.

Also have a look at proxying your webserver to ensure security.

Getting CPU & RAM Usage.

$context = [
  "http" => [
      "method" => "GET",
      "header" => "Authorization: <auth code here>"
  ]
];

$console = file_get_contents("http://localhost:35565/", false, stream_context_create($context))
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://localhost:35565/");
curl_setopt($ch, CURLOPT_POST, 1);
$authHeaders = array(
  "Authorization: <auth code here>",
  "Content-type: application/json"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $authHeaders);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("command" => "command here", "user" => "optional user here")));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);
webSocket = new WebSocket('ws://localhost:35565', 'auth code here');
webSocket.onmessage = (message) => {
    let line = message.data;
    console.log(line)
};

webSocket.send(JSON.stringify({"action": "command", "command": "command here", "user": "optional user here"}))

Important Note: You must have a ping/pong event every ~10 seconds to keep the websocket connection alive. To do this put ping for the action field. The server will return a pong in raw text. I advise you to have an if statement to make sure you filter it out.

In the websocket, specify the action field as either: start, stop, restart or kill.

In HTTP, specify the command field as either start, stop or restart.

Note: You can still pass the user field.

All requests include a Authorization header with the auth code you set in the start.js file.

Pass the authentication code in the protocall for websockets. See Above

It is highly recommended that you proxy your webserver as this does not support https at the moment. Here are some articles on how you can do that.

Setting up NGINX as your proxy server with NodeJS apps

How to Setup Apache As Frontend Proxy for Node.js

Make a GET request to /usage to return a json array of the server's current CPU load and ram.

$context = [
  "http" => [
      "method" => "GET",
      "header" => "Authorization: <auth code here>"
  ]
];

$usage = file_get_contents("http://localhost:35565/usage", false, stream_context_create($context))
$usage = json_decode($usage, true);

API

Events

Methods

Register an event by doing:

server.on("event name", (params) => {
  // do stuff
})

Help

To get help feel free to message me on discord Chezzer#6969.