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

atropa-server

v0.5.2-1

Published

A simple http server for node with autoindexing and lazy module loading.

Downloads

57

Readme

Atropa Server

A simple http server for node with autoindexing and lazy module loading.

Overwhelmed by enterprise level server modules like Express and Flatiron? Me too. I don't want to read an entire dictionary and hire a team of developers to support my applications so, I rolled my own dead simple server. The main idea here is that Atropa Server will be as easy to use as just dropping files into a directory and requesting them in the browser. No crazy routing, no convoluted templating systems crammed down your throat, and absolutely no overarching philosophy on how your application should be structured. Just do whatever the hell you want without screwing around for hours re-learning how to do what you already know how to do.

So, you're probably wondering just how easy it is to get set up with the Atropa Server. Well, you just run npm install atropa-server and you're all set. Toss your HTML files in your project folder and run "node_modules/.bin/atropa-server" 8888 . The prompt will tell you the address and port your server is running on. If you've got an index.html file in your project folder then the server will find it and serve it up or, you'll see an absolutely beautiful listing of your project's files and directories. As an added bonus, this server uses the mime module to automatically serve files with the proper content type. See the documentation on the mime module for instructions on adding custom mime types. To specify a different port, change 8888 in the example to a different port number. To specify a different root directory for your webserver change the second parameter from . to an absolute path.

Now I know what you're thinking, "sure, static files are all fine and good but..." Don't worry, you can have dynamically generated content and it's dead simple too! You just write up regular javascript files but instead of using the extension js, use jsn. The only requirement is that jsn files export a single function that accepts two parameters. The first parameter given to the function will be the response object, which you will use to send your server's response to arbitrary requests made to your jsn file. The second parameter given to the function will be the request object, jam packed with everything you'll ever want to know about the request made to your server. For an example of a basic jsn file scroll down. For details on the request object see http://nodejs.org/api/http.html#http_http_incomingmessage. For details on the responseobject see http://nodejs.org/api/http.html#http_class_http_serverresponse.

Basic Usage

Set up a node project with the simplest structure possible:

Note that there is a full example project you can copy and run npm install, npm start on. It's in the examples folder.

myProjectFolder
  |
  |___node_modules
  |       |
  |       |___atropa_server
  |
  |___index.html
  |
  |___server.js
  |
  |___serverSideJavaScript.jsn
  |
  |___package.json

In index.html put whatever html content you want.

In server.js do:

var atropaServer = require('atropa-server');
// starting the server on port 9999
// an optional second parameter for setting the server root
// as an absolute path may be specified. The server root 
// defaults to `path.dirname(process.mainModule.filename)`
atropaServer.start(9999);

In serverSideJavaScript.jsn do:

module.exports = function (response, request) {
    // change text/plain to text/html if you're sending html
    // change text/plain to application/json if you're sending json
    response.writeHead(200, {'Content-Type' : 'text/plain'});
    response.write('hello', 'utf8');
    response.end();
};

After that run node server.js and open a web browser to http://localhost:9999 and whatever content you've put into index.html will magically appear! Navigate to http://localhost:9999/serverSideJavaScript.jsn and BANG! you'll see the wonderful wonderment of dynamically lazily loading your module. Go ahead and make all the jsn files you want and name them whatever you want. They'll be cached the first time they're called so they don't cost anything until they're needed and only cost something once! Of course any changes to jsn files will require you to restart the server if the changed file has been cached already.

Enjoy!

☭ Hial Atropa!! ☭