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

maishu-nwsp

v2.8.3

Published

基于 nodejs 的 MVC 框架

Downloads

3

Readme

Node Web Server Plus

前言:作者在 nodejs 开发的时候发现一个问题,就是没有一个好用一点的 Web Server(类似于 IIS) ,有时候写个简单的东西,都要安装一大堆东西。于是作者开发一款 Node Web Server 。 然后发现还是不够好用,但是又不想把 Node Web Server 的代码搞得太复杂,于是对 Node Web Server 进行二次封装,开发了这个名为 Node Web Server Plus 的软件。

Node Web Server 的加强版本,再 Node Web Server 的基础上集成更多的功能。

  1. 提供命令行启动
  2. 提供了配置文件进行设置
  3. 集成了 Babel,把 ts,js 转换为 amd js
  4. 集成了 MVC 功能
  5. 集成了 Less,Less 转 CSS
  6. 提供了插件加载机制

安装使用

软件提供了 npm 的安装方式,在控制台输入下面的命令

npm i -g maishu-nwsp

软件提供了命令行的方式来使用

nwsp -d <website path> -p <port>

-d 必填,后面的参数 <website path> 为网站文件夹 -p 可选,后面的参数 <port> 为网站端口,默认值为 9868

网站目录

一个典型的网站文件夹应该如下:

根目录
├── controllers
|   └── home.js
├── node_modules
├── public
|   └── dynamic
|   └── index.html
└── package.json
  • controllers 文件夹用来放置控制器文件
  • public 文件夹为公开的文件夹,可以通过 http 请求进行访问
  • dynamic 用于存放动态脚本文件,关于动态脚本文件,参考 Node Web Server

示例

下面的示例演示一个最为简单的网页显示

创建一个名为 demo 的文件夹如下:

demo
├── public
|   └── index.html

index.html 文件

<html>
  <head> </head>
  <body>
    <h1>Hello World</h1>
  </body>
</html>

运行命令

nwsp -d demo

在浏览器输入 http://127.0.0.1:9868 可以看到

Hello World

TS 文件的转换

文件夹如下

demo
├── public
|   └── index.html
|   └── index.ts

index.html 文件

<html>
  <head></head>
  <body>
    <script src="./index.ts"></script>
  </body>
</html>

index.ts 文件

let hello: string = 'Hello'
let world: string = 'World'
document.body.innerHTML = hello + ' ' + world

运行命令

nwsp -d demo

在浏览器输入 http://127.0.0.1:9868 可以看到

Hello World

在浏览器输入 http://127.0.0.1:9868/index.ts 可以看到

'use strict'

let hello = 'Hello'
let world = 'World'
document.body.innerHTML = hello + ' ' + world

LESS 文件转换

文件夹如下

demo
├── public
|   └── index.html
|   └── index.less

index.html 文件内容如下:

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="./index.less" />
  </head>
  <body>
    <h1>Hello World</h1>
  </body>
</html>

index.less 文件内容如下:

@color: red;

h1 {
  color: @color;
}

运行命令

nwsp -d demo

在浏览器输入 http://127.0.0.1:9868 可以看到红色的 ”Hello World“

动态脚本

node-web-server 支持使用 js 编写的动态脚本文件,动态脚本文件需要放在名为特定的文件夹,该文件夹默认为 dynamic,可以同通过配置修改该文件夹路径。

示例

文件夹如下

demo
├── public
|   └── dynamic
|       └── hello-world.js

hello-world.js 文件如下

exports.default = function () {
    return {
        content: "hello world",
        headers: { "Content-Type": "text/plain" }
    }
}

在浏览器输入:http://127.0.0.1:9868/dynamic/hello-world.js 可以看到:

hello world