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

web-node-server

v0.0.11

Published

Achieve node server's domain name resolution and web application's router

Downloads

1

Readme

nodeserver

Achieve node server's domain name resolution and web application's router

What is realized

1.This is a simple node http server,achieve a mapping for server and domain name,than a mapping for the static file and API route

2.right response for get, post, put, delete method,then submit the params in route query string and form data to your node backend.

Setup and run

Global module

make sure you have global installed node.

Initialization

$ sudo npm install web-node-server

Configure

You should configure server in this directory, specific method is:

// configure server constant
// config.js
exports.constant = {
  // default port
  port: 9999,
  // welcome page's configure
  host: {
    backend: path.join(__dirname, '/../default/'),
    frondend: path.join(__dirname, '/../default/'),
    baseTemp: 'welcome.html'
  }
};
// Binding to the domain name
exports.serv = {
  // sites' domain name
  'localhost1': {
    // sites' backend workspace
    backend: '/Users/pg/demo/nodeserver/default/',
    // sites' frondend workspace
    frondend: '/Users/pg/demo/nodeserver/default/',
    // sites' static file entrance
    baseTemp: 'demo.html'
  }
};

At backend workspace (previously defined workspace) create config.js. Write the site routing information

// project_url/config.js
// Define a API's url,all get method's API are in app.url.get object,the key is route url,value is a function which will be running. Than define post, put, delete route.
exports.app = {
  url: {
    'get': {
      '/api': list.get
    },
    'post': {
      '/api': list.post
    },
    'put': {
      '/api': list.put
    },
    'delete': {
      '/api': list.remove
    }
  }
}

var list = {
  get: function(send, res, routeParams, getParams) {
    res.status = 200;
    res.data = {
      message: 'yes! this is a response data with get method',
      routeParams: routeParams,
      getParams: getParams
    };
    return send(res); // return application/json
  },
  post: function(send, res, routeParams, getParams, formData) {
    res.status = 200;
    res.html = '<html></html>';
    return send(res); // return text/html
  },
  delete: function(send, res, routeParams, getParams, formData) {
    res.status = 302;
    res.url = '/article';
    return send(res); // return 302 to a url
  }
}

run

// In root directory
node web-node-server.js

// In project directory (run this directory only, with local config)
// you may add web-node-server into you package.json
config = {
  'localhost': {
    backend: __dirname + '/api/',
    frondend: __dirname + '/web/',
    baseTemp: 'index.html'
  }
}
var server = require('web-node-server');
server.start(config);

Learn more

There are some example in welcome page about get, post, put, delete method's using. You can reference

you can give me your suggestion in github.

The basic file directory structure

If any changes please update this section

.
├── config.js           ... server's domain example configure
├── index.js            ... example startup code
├── nodeserver.js       ... define response callback,than start server
├── router.js           ... distinguish different request, make different treatment
├── tool                ... gadgets
└── default             ... default welcome page
    ├── config.js       ... example route configure
    ├── demo.html       ... demo page about a demo configure
    └── welcome.html    ... welcome page,the function demonstration