Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »


1.1.1 • Public • Published
Achieve is a modern HTTP server that runs on Node.js and uses JavaScript Servlets to initiate back end processing.

Achieve Node.js Server with JavaScript Servlets

Achieve is a modern HTTP server that runs on Node.js and uses JavaScript Servlets to initiate back end processing. It is available via npm.

For a more detailed quick start tutorial, click here

Achieve is part of the High Level Logic Project.

Features Summary

Regular HTTP features:

  • Delivers static content.
  • Unlimited MIME support.
  • Runs back-end JavaScript programs (via JavaScript Servlets).
  • Supports defaults index.html, index.htm, index.js
  • Supports browser caching. (ETag)
  • Supports compression with ss caching. (gzip,deflate)
  • Streaming audio/video files.

Special Features:

  • No knowledge of Node.js required to start using JS Servlets.
  • Little knowledge of JavaScript required to start using JS Servlets.
  • Servlets handle HTTP Response. App just uses return statement.
  • Useful app error reports can be displayed in browser console.
  • Automatic reload of modified files.
  • Servlet Context Object allows developer to take complete control.
  • Node.js environment configuration. (development,production)
  • Configurable apps folder path and path to the ROOT application.

Quick Start

Install Node.js v8.1 or later. (Developed / tested with v8.9.4)

Running Achieve (simplest form):

const server = require('achieve');
server.listen();  // defaults to port 80

By default, the base application directory is the same as the file you create to start the server. You can set the base application directory with the setAppPath option below.

Running Achieve with options:

const server = require('achieve');

server.setAppPath("c:/myachieve/myapps"); // set base directory for all applications server.setRootDir('root'); // set a subdirectory under the root directory for THE ROOT application server.setCaching(true); // turn browser caching support on server.setCompress(true); // compress static resources server.showMimeTypes(); // Show the current list of supported MIME Types server.addMimeType("pub","application/x-mspublisher"); // add an unsupported MIME type server.addAVMimeType("wav","audio/wav"); // add an unsupported AV MIME type server.setNodeEnv("development"); // set Node environment

server.listen(8989); // listens on port 8989

Hello World Servlet:

// Save this code in file index.js in the apps directory ("application base" - directory where you are running the server)
exports.servlet = function (context) { return "Hello World!"; // Achieve handles the response. }

Display results in browser: http://localhost:8989 (assuming port 8989 and the file is named index.js.

Note also that the url is index, without the .js extension. With the .js extension, http://localhost:8989/index.js the file will be served.

Achieve will reload your programs when they've been modified. No need to restart the server.

Application Code Error Messages in browser console:

Modify your servlet to cause an error by deleting a few characters from the end of the return statement: return "Hello World. Refresh the page.

To see how to receive error message in the browser's console, save this HTML file and save it to your apps directory as index.htm. Open the inspector in your browser and click on the console tab. Then reload http://localhost:8989 On the browser side, the trick is in the callback() function.

Access parameter values that were sent with the request:

    var myParm = context.parms.myParm;  // or
    var myParm = context.parms['myParm'];

Servlets can use other functions:

exports.servlet = function (context)  {
  return hello();
function hello ()  {
   return "Hello World!";

Servlets can use functions in other files.

// in otherfile.js
exports.hello () {
  Return "Hello World!";

// in myservlet.js
exports.servlet = function (context) {
  var other = context.load("otherfile.js");  // Extends servlet features to otherfile; reloads if cache is stale.
  return other.hello();

The Servlet Context

You can use the Servlet Context to take control of your back end process. The Servlet Context contains:

  context.request    // The session request object.
  context.response   // The session response object.
  context.parms      // Parameters sent with the request
  context.dirPath    // The current application path on your computer
  context.load       // The JavaScript Servlet load() method (see above)
  context.allowAsync // Set to true if you handle the response in an asynchronous process.


npm i achieve

Downloadsweekly downloads










last publish


  • avatar
Report a vulnerability