{"id":12154,"library":"tomahawk","title":"Tomahawk HTTP Server","description":"Tomahawk is a minimalist HTTP server designed for Node.js. It provides functionality for serving static content, executing CGI scripts, and defining REST API routes programmatically. Currently at version 0.2.1, its development appears to be abandoned, with its `engines` field explicitly requiring Node.js versions `>= 0.8.0 < 0.11.0`. Node.js 0.8.0 was released in June 2012, and 0.11.0 in March 2013, making this package incompatible with all modern Node.js runtimes. Its key differentiator was its simplicity and dual nature as both a command-line utility for static/CGI serving and a module for basic REST API creation, offering a lightweight alternative during its active period. Compared to contemporary HTTP server solutions, Tomahawk lacks modern features, performance optimizations, and security updates.","status":"abandoned","version":"0.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/hbouvier/tomahawk","tags":["javascript"],"install":[{"cmd":"npm install tomahawk","lang":"bash","label":"npm"},{"cmd":"yarn add tomahawk","lang":"bash","label":"yarn"},{"cmd":"pnpm add tomahawk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Tomahawk is a CommonJS module and does not support ES Modules ('import'). The `create` method is accessed from the default export.","wrong":"import { create } from 'tomahawk';","symbol":"create","correct":"const tomahawk = require('tomahawk');\nconst app = tomahawk.create({port: 8080}).start();"},{"note":"HTTP methods like `get`, `post`, `put` are exposed on the `app` instance returned by `tomahawk.create()`, not directly on the `tomahawk` module.","wrong":"tomahawk.get('/api/v1/resource', ...);","symbol":"app.get","correct":"app.get('/api/v1/resource', function (req, res) { /* ... */ });"}],"quickstart":{"code":"const tomahawk = require('tomahawk');\nconst path = require('path');\n\n// A simple database for demonstration\nconst database = {\n  captains : {\n    \"jim\"    : \"James Tiberius Kirk\",\n    \"picard\" : \"Jean-Luc Picard\"\n  },\n  starShips : {\n    \"jim\": \"NCC1701-A\",\n    \"picard\": \"NCC1701-D\"\n  }\n};\n\n// Define routes dynamically\nconst routesModule = function () {\n  function routes(app, config, io) {\n    // GET all captains or a specific one\n    app.get('/api/v1/captain/:id?', function (req, res) {\n      const withStarship = req.query.starship === 'true';\n      if (req.params.id) {\n        const captainData = database.captains[req.params.id];\n        if (captainData) {\n          res.json(withStarship ?\n            {id: req.params.id, name: captainData, starship: database.starShips[req.params.id]} :\n            {id: req.params.id, name: captainData});\n        } else {\n          res.writeHead(404, {'Content-Type': 'application/json'});\n          res.end(JSON.stringify({ error: 'Captain not found' }));\n        }\n      } else {\n        res.json(database.captains);\n      }\n      res.end();\n    });\n\n    // PUT (create/update) a captain\n    app.put('/api/v1/captain/:id', function (req, res) {\n      // In a real app, req.body would be parsed by middleware\n      // For this example, assuming req.body is already a string/object\n      const newCaptainName = req.body || req.params.id; // Simplified for demo\n      database.captains[req.params.id] = newCaptainName;\n      res.json({ status: 'success', id: req.params.id, name: newCaptainName });\n      // io.sockets.emit('new:captain', { id: req.params.id, name: newCaptainName }); // Example from original, 'io' is undefined here\n      res.end();\n    });\n\n    console.log('REST routes registered.');\n  }\n  return routes;\n};\n\n// Create and start the server\nconst app = tomahawk.create({\n  port: process.env.PORT || 8080,\n  www: path.join(__dirname, 'public'), // Serve static files from a 'public' directory\n  routes: [routesModule()] // Pass the route definitions\n}).start();\n\nconsole.log(`Tomahawk server running on http://localhost:${app.config.port}`);\nconsole.log('Try visiting /api/v1/captain/jim or /api/v1/captain?starship=true');\nconsole.log('To test PUT: curl -X PUT -H \"Content-Type: application/json\" -d \"Arthur Dent\" http://localhost:8080/api/v1/captain/arthur');","lang":"javascript","description":"This quickstart demonstrates how to use Tomahawk programmatically to set up a basic HTTP server, serve static files, and define REST API routes (GET, PUT) for a simple in-memory database. It includes an example of routing with path parameters and query parameters."},"warnings":[{"fix":"Do not use Tomahawk in any modern Node.js project. It is effectively abandoned. Consider modern alternatives like `http-server`, Express.js, Fastify, or Koa.js for static file serving or API development.","message":"Tomahawk explicitly requires Node.js versions `>= 0.8.0 < 0.11.0`. Modern Node.js versions (e.g., v12+) are incompatible, leading to runtime errors, module resolution issues, or unexpected behavior due to significant API changes over the past decade.","severity":"breaking","affected_versions":">=0.2.1"},{"fix":"Replace Tomahawk with a actively maintained and secure HTTP server library or framework. There are no security fixes or updates available for this package.","message":"The package is unmaintained, with the last publish being over 11 years ago (December 2014) and targeting Node.js versions from 2012-2013. This means it contains numerous unpatched security vulnerabilities, is not compatible with current web standards, and should not be used in any production environment or publicly accessible service.","severity":"breaking","affected_versions":">=0.2.1"},{"fix":"Ensure all imports for Tomahawk use the CommonJS `require()` syntax (e.g., `const tomahawk = require('tomahawk');`).","message":"Tomahawk uses CommonJS `require()` for module imports. It does not support ES Modules (`import`). Attempting to use `import` syntax will result in a runtime error.","severity":"gotcha","affected_versions":">=0.2.1"},{"fix":"Thoroughly validate and sanitize all user inputs passed to CGI scripts. If using CGI, prefer dedicated, secure solutions rather than an unmaintained package. Better yet, avoid CGI entirely and use a modern API framework.","message":"CGI functionality relies on external shell commands and configurations. Incorrectly configured CGI routes, especially those accepting user input, can lead to severe command injection vulnerabilities if not properly sanitized.","severity":"gotcha","affected_versions":">=0.2.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Run `npm install tomahawk` or `npm install -g tomahawk` if using it as a global CLI tool.","cause":"The 'tomahawk' package is not installed or the Node.js runtime cannot locate it.","error":"Error: Cannot find module 'tomahawk'"},{"fix":"Ensure you call HTTP methods on the `app` instance created by `tomahawk.create()`. Example: `const app = require('tomahawk').create({port:8080, routes: [...]}).start(); app.get(...)`.","cause":"Attempting to call an HTTP method (like `get`) on the `tomahawk` module directly instead of on the server instance returned by `tomahawk.create().`","error":"TypeError: app.get is not a function"},{"fix":"Stop the application currently using the port, or configure Tomahawk to listen on a different port using the `--port` CLI option or the `port` option in the programmatic `create` method (e.g., `port: 3000`).","cause":"The specified port (e.g., 8080) is already in use by another application on your system.","error":"Error: listen EADDRINUSE :::8080"},{"fix":"Tomahawk is a CommonJS module and cannot be directly imported into an ES Module. You must use a Node.js environment configured for CommonJS (e.g., a `.js` file without `\"type\": \"module\"` in `package.json`). Or, preferably, switch to a modern server library that supports ESM.","cause":"Attempting to use CommonJS `require()` syntax in an ES Module context.","error":"ReferenceError: require is not defined (when using import syntax in a .mjs file or with 'type: module' in package.json)"}],"ecosystem":"npm"}