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

simple-node-cgi

v1.0.0

Published

CGI helper to run nodejs scripts on your Apache Server

Downloads

2

Readme

CGI Helper for Apache Servers

Disclaimer: This project is right now at a very early stage. Do not use for production yet.

simple-node-cgi provides a simple way of running your nodejs scripts on your backend without the need of having to spin up an extra webserver. Just write your script and copy it to your Webserver running Apache, just like you would do with a php script.

Getting Started

There are a lot of ways to make this work. I'll explain here the method I reagard as most versatile and easy to use.

Step 1

Install node Version > TODO on your webserver. https://nodejs.org/

Step 2

Install simple-node-cgi globally by running sudo npm install -g simple-node-cgi

Step 3

Create a file named .htaccess at the root of your html directory and add these lines to activate simple-node-cgi

# Activate simple-node-cgi
Options +ExecCGI
AddHandler cgi-script "mjs"

Step 4

Write your node script using node. The script needs to start with the following 3 lines and use import instead of require() for imports

#!/usr/bin/node
import server from 'simple-node-cgi';
const {req, res} = server({debug: true});

Step 5

Finish by calling res.send("Hello World!");

Step 6

Save your file with the extension .mjs and copy it to your Apache Server.

Step 7

Make your file executable by calling sudo chmod a+x your-file.mjs.

Step 8

Call your script by visiting your server www.yourserver.com/your-file.mjs

API

I designed the API to be similar to the node express API.

request.init({
    debug?: boolean // if set to true all uncaught errors will be printed in detail
}): void
type request = {

    ...

    query: {},
    send: SendType

}
type SendType = (body: string, headers?: HeadersType) => void
type HeadersType = {

}

Motivation & Alternatives

I wanted to write and deploy scripts and small concepts without the hassle of having to spin up and map a whole node express server for every single small standalone script. I wanted something that was as easy to use as PHP, but with the syntax and concept of node-express. Thats the reason I've created this.

I've found two alternatives doing something similar. One is node-cgi and the other is cgi-node. However the approach they took was more like having a php-like templating syntax. So they are more like PHP for node.

TODO

These are the next items which have to be done

  • Rewrite in TypeScript
  • test if working with deno
  • make the script work without having to call chmod on them each time the file gets replaced
  • block public access to all folders called node_modules by entry in .htaccess file
  • create compatibilty with require() as well

License

Begin license text.
Copyright 2022 Marcel Frederik Niessen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

End license text.