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

jasny

v0.1.1

Published

Jasny http web framework for nodejs

Downloads

7

Readme

jasny

Jasny http web framework for nodejs written and for use with TypeScript.

Jasny is a TypeScript framework for making websites. It's best when you use it with your TypeScript projects although you don't have to use TypeScript in order to work with it.

Example main file (index.ts):

/// <reference path="typings/jasny/jasny.d.ts" />
/// <reference path="typings/node/node.d.ts" />

import jasny = require('jasny');
import path = require('path');
import Config = require('./Config');

var server:jasny.Server = new jasny.Server();

server.config.publicDir = path.resolve(__dirname, '..', 'public');
server.config.port = 4601;
server.config.allowCORSFromAll = false;

server.di.register('config', new Config());

server.addRoute('GET /file/:fileName', require('./actions/file/GetFile'));

server.listen();
console.log('Gaad-TabUI listening on port '  + server.config.port);
export = server;

Let's examine the code above line by line.

/// <reference path="typings/jasny/jasny.d.ts" />

In this line we are making a reference to declaration file. This file is shipped to you with the module. You can create a symbolic link to point to node_modules/jasny/typings/jasny folder if you want to have it in your typeings directory.

var server:jasny.Server = new jasny.Server();

We are creating new instance of the Server class. This is the facade for our application.

server.config.publicDir = path.resolve(__dirname, '..', 'public');

If we set the publicDir property on the config then the server will start serving static files. If we don't want to serve statics then leave it blank.

server.config.port = 4601;

Port to listen to.

server.config.allowCORSFromAll = false;

If we want to allow Cross Origin Resource Sharing from every server then we can just set this variable to true.

server.di.register('config', new Config());

Here we are registering the config object into dependency injection container.

server.addRoute('GET /file/:fileName', require('./actions/file/GetFile'));

We are adding the route class. Every Route action has to be a class that inherits from jasny.Action. You can use dependency injection in the Actions

server.listen();

Finally we start to listen.

Example action class (GetFile.ts):

/// <reference path="../../typings/node/node.d.ts" />
/// <reference path="../../typings/jasny/jasny.d.ts" />

import jasny = require('jasny');
import fs = require('fs');
import Config = require('../../Config');

class GetFile extends jasny.Action {

  //We declare what we want to inject.
  //If the variable name is different then the registered bean name (for example: 'cfg') then
  //we should define it like that:
  //public inject:any[] = [{cfg: 'config'}];
  //otherwise:
  public inject:any[] = ['config'];

  private config:Config;

  constructor() {
    super();
  }

  private ready() : void {
    //the config variable is ready now
  }

  public execute():void {
    fs.readFile('file.txt', (buffer) => {
      this.res.send(buffer.toString());
    });
  }

}

export = GetFile;