
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
This module is one of my earliest gigs and is mostly unjustified overhead.
A dead-simple HTTP server class. A wrapper to Node's native HTTP server, enables you to easly create and control an HTTP server.
const http = require('http');
const server = http.createServer(function (req, res) {
res.end('Hello beautiful world');
});
server.listen(8080, '127.0.0.1', function () {
console.log('Listening at 127.0.0.1:8080');
});
require('a-server')().start((req, res) => {
res.end('Hello beautiful world');
});
.start()
, .stop()
etc).$ npm install a-server --save
const aServer = require('a-server');
const myServer = aServer(options);
myServer.start(function (req, res) {
res.end('Hello beautiful world');
});
If all you need is only one server, you can:
const server = require('a-server')(options);
server.start((req, res) => {
res.end('Hello beautiful world');
});
or even:
require('a-server')(options).start((req, res) => {
res.end('Hello beautiful world');
});
You can create multiple servers:
const aServer = require('a-server');
const myServer1 = aServer({port:8181});
const myServer2 = aServer({port:8282});
host
<String>Begin accepting connections on the specified hostname. If the hostname is null
, the server will accept connections on any IPv6 address (::)
Default: process.env.IP (if exists) or '127.0.0.1'
.
port
<Number>Begin accepting connections on the specified port.
Default: process.env.PORT (if exists) or 8080
.
https
<Object>An HTTPS options object. Read more.
Default: false
(HTTP server)
timeout
<Number>Sockets idle timeout limit in milliseconds (Node's default is 2 minutes)
Default: 5000
logs
<Boolean>Basic default logs when the server starts, when it stops and when a new app is being mounted.
Default: true
To setup a new a-server instance with its own individual options:
const aServer = require('a-server')();
const myServer = aServer({
timeout: 10000
logs: false,
});
myServer.start();
To change a-server's global defaults:
const aServer = require('a-server');
/* NOTE: This will be applied for ALL new a-server instances */
aServer.defaults.timeout = 10000;
aServer.defaults.logs = false;
.start(app)
Start listening for client requests.
app
is a request-handler, a function for handling the request
and the response
.
After the server has started the .onStart()
hook function gets called (see hooks below).
example:
const server = require('a-server')(options);
function app (req, res) {
res.end('Hello beautiful world');
}
server.start(app);
.stop([callback])
Stops the server from accepting new requests.
callback
(function) is an optional argument. It will get called after the .onStop()
hook (see hooks below).
example:
const server = require('a-server')();
function app (req, res) {
res.end('Hello beautiful world');
}
server.start(app);
// ...
server.stop(function () {
console.log('Goodbye!');
});
.restart([newApp])
Stops the server and starts it again with an optional new app function (a new request-handler).
Calls .stop()
and .start()
methods (meaning: runs the onStop
and onStart
hooks. Read more about hooks.
example:
const aServer = require('a-server')();
function app_1 (req, res) {
res.end('good morning!');
}
function app_2 (req, res) {
res.end('good evening!');
}
aServer.start(app_1);
// ...
aServer.restart(app_2);
.remount(newApp)
Replaces the server's current request-handler with a new one.
Does NOT call .stop()
and.start()
methods.
example:
const aServer = require('a-server')();
function app_1 (req, res) {
res.end('good morning!');
}
function app_2 (req, res) {
res.end('good evening!');
}
aServer.start(app_1);
// ...
aServer.remount(app_2);
.kill()
Stops the server from accepting new requests and kill its props and handlers. Calls the native server.unref()
.
A killed server cannot be started again.
example:
const aServer = require('a-server')();
function app (req, res) {
res.end('Hello beautiful world');
}
aServer.start(app);
// ...
aServer.kill();
// ...
aServer.start(app_1); // --> error
NOTE: a-server is NOT an instance of EventEmitter.
a-server has two event-like hooks:
onStart
type: <Function>
default: None.
A callback function to run after the server starts.
Gets called with the server
instance as its only argument.
onStop
type: <Function>
default: None.
A callback function to run after the server stops.
Gets called with the server
instance as its only argument.
Simply put your callback functions in those placeholders:
const myServer = require('a-server')();
myServer.onStart = function (myServer) {
// e.g. OPEN a databse connection
};
myServer.onStop = function (myServer) {
// e.g. CLOSE a databse connection
};
myServer.start((req, res) => {
res.end('hello');
});
You have access to the underlying native HTTP server using the _server
property:
const aServer = require('a-server')();
// the native HTTP server
console.log(server._server);
FAQs
A dead-simple HTTP server class.
The npm package a-server receives a total of 2 weekly downloads. As such, a-server popularity was classified as not popular.
We found that a-server 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.