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

sectserver

v1.0.2

Published

An easy to use, fast and simple web framework for node.js with built-in template engine.

Downloads

4

Readme

SectServer

An easy to use, fast and simple web framework for node.js with built-in template engine.

npm i sectserver

const sectserver = require("sectserver")

var app = sectserver();

app.set('static dir', __dirname + '/public');
app.set('views dir', __dirname + '/views');

app.add({
  url: '/',
  handler: (req, res) => {
    res.send('Hello, World!');
  }
})

app.listen(3000);

Example:

const sectserver = require("sectserver")

var app = sectserver();

app.set('static dir', __dirname + '/public');
app.set('views dir', __dirname + '/views');

app.add({
  url: '/',
  handler: (req, res) => { // > /
    res.render('Hello {globe}, My Name Is: {cool_name}!', {globe: `World`, cool_name: `SectServer`}); // Default Render Engine: SectPlating, See Guide To Change The Default.
  }
})

app.add({ // :one = required, :one? = optional
  url: '/test/:one?', // > /test/world?two=SectServer
  handler: (req, res) => {
    res.render('Hello {one}, My Name Is: {two}!', {one: `${req.params.one}`, two: `${req.query.two}`});
  }
})

app.add({
  url: '/body', // > /body
  handler: (req, res) => {
    res.json(`${JSON.stringify(req.body)}`);
  }
})

app.add({
  url: '/hi', // > /hi
  handler: (req, res) => {
    res.send('Hello!');
  }
})

app.add({
  url: '/end', // > /end
  handler: (req, res) => {
    res.end('The End!');
  }
})

app.listen(8080);

Guide:

After you install the module, require it:

const sectserver = require('sectserver');

initialize your app:

let app = sectserver();

If you want, change the default configs:

app.set('template', 'pug') /* view engine, see: https://www.npmjs.com/package/consolidate#supported-template-engines for a list of supported view engines | view engine defaults to: sectplating */
.set('static dir', './public') /* static content directory (.css, .js, .json...)*/
.set('views dir', './views'); /* views directory ( .pug, .haml, .html) */
app.locals.foo = 'bar'; /* app.locals is an object that you can use (and call) it everywhere (middlewares, routers, renders...)*/

Now, you can add the middlewares you want

app.add(compress()) /* data compress*/
.add(favicon('./public/favicon.ico')) /* serve favicon and cache it*/
.add(app.serveStatic('./public')) /* serve static content */
.add(bodyParser.json()) /* data parser to req.body */
.add(bodyParser.urlencoded({ extended: true })) /* same above */
.add(cookieParser()) /* cookies parser to req.cookies */

you can set routers for a path (or all) and a method through the 'app.add' method.

| Param | Object | |-----|---------| | req | Request. | | res | Response. | | next | Next middleware to call. |

app.add(
    (req,res,next) => {
        res.render("index", { title: 'My Title Page'});
    }
);

##Response instance of http.ServerResponse.

res.send('foo'); /* => send 'foo' */
res.status(404); // response status is 404
res.status(404).send('Not Found'); /* => send error 404 and 'Not Found' */
res.sendStatus(404); /* => same above */
res.json({'foo': 'bar'}) /* => send '{'foo':'bar'}'*/
res.sendFile('/test.json') /* => send the content of file /public/test.json (or your static dir)*/
res.render('index',{foo: 'bar',bar: 'foo'}) /* => send the view index.pug (default, or your views engine)*/
res.redirect('/foo') /* => redirect users to /foo */
res.locals /* => is similar to app.locals but only lives in current request (you can refresh it inn each request through middlewares) */

##Router Its a handler for your paths. You can to nest routers on the app.

let router = app.Router();

router.add({
        url: '/path', // > /path
        method: 'GET',
        handler: (req,res,next) => { /* anything */}
    })
    .add({
        url: '/path', // > /path
        method: 'POST',
        handler: (req,res,next) => { /* anything */}
    })
    .add({
        url: '/path', // > /path
        method: 'PUT',
        handler: (req,res,next) => { /* anything */}
    })
    .add({
        url: '/path', // > /path
        method: 'DELETE',
        handler: (req,res,next) => { /* anything */}
    })
    .add({
        url: '/path', // > /path
        method: 'PUT',
        handler: (req,res,next) => { /* anything */}
    })
    .add({
        url: '/user/:id', // > /user/48
        handler: (req,res,next) => { /* req.params.id */}
    })
    .add({
        url: '/asset/', // > /asset?name=logo.png&from=images
        handler: (req,res,next) => { /* req.query.name, req.query.from */}
    })

/* incorpore to your app */
app.add({
    url: '/foo',
    handler: router
    })