# maishu-node-mvc

> 基于 nodejs 的 MVC 框架

Latest version **2.33.0** (published 2022-05-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install maishu-node-mvc
pnpm add maishu-node-mvc
yarn add maishu-node-mvc
bun add maishu-node-mvc
```

Provides the commands `node-mvc`, `node-static`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.33.0 |
| Published | 2022-05-12 |
| First published | 2018-12-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | mai.shu |
| Maintainers | ansiboy |

## Links

- npm: https://www.npmjs.com/package/maishu-node-mvc
- Repository: https://github.com/ansiboy/node-mvc
- Homepage: https://github.com/ansiboy/node-mvc#readme
- Issues: https://github.com/ansiboy/node-mvc/issues
- npm.io page: https://npm.io/package/maishu-node-mvc

## Dependencies (14)

- [less](https://npm.io/package/less.md) ^3.13.0
- [sass](https://npm.io/package/sass.md) ^1.32.12
- [json5](https://npm.io/package/json5.md) ^2.1.3
- [yargs](https://npm.io/package/yargs.md) ^16.2.0
- [log4js](https://npm.io/package/log4js.md) ^6.3.0
- [install](https://npm.io/package/install.md) ^0.13.0
- [inquirer](https://npm.io/package/inquirer.md) ^7.3.3
- [is-class](https://npm.io/package/is-class.md) 0.0.5
- [maishu-nws-js](https://npm.io/package/maishu-nws-js.md) ^1.3.2
- [maishu-router](https://npm.io/package/maishu-router.md) ^1.4.2
- [maishu-nws-mvc](https://npm.io/package/maishu-nws-mvc.md) ^1.19.0
- [maishu-toolkit](https://npm.io/package/maishu-toolkit.md) ^1.6.6
- [@babel/plugin-proposal-decorators](https://npm.io/package/@babel/plugin-proposal-decorators.md) ^7.12.12
- [@babel/plugin-transform-react-jsx](https://npm.io/package/@babel/plugin-transform-react-jsx.md) ^7.12.12

## Recent versions

- 2.33.0 (latest) — 2022-05-12
- 2.32.0 — 2022-04-09
- 2.31.0 — 2022-04-09
- 2.30.0 — 2022-03-21
- 2.21.0 — 2021-10-22
- 2.20.0 — 2021-07-16
- 2.19.4 — 2021-06-08
- 2.19.3 — 2021-05-20
- 2.19.2 — 2021-05-20
- 2.19.1 — 2021-05-07
- 2.18.7 — 2021-04-10
- 2.18.4 — 2021-04-07
- 2.18.2 — 2021-03-18
- 2.18.0 — 2021-03-13
- 2.17.0 — 2021-03-10
- … 119 more at https://npm.io/package/maishu-node-mvc/versions

## 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](https://github.com/ansiboy/node-web-server) 的加强版本，再 Node Web Server 的基础上集成更多的功能。

1. 提供命令行启动
1. 提供了配置文件进行设置
1. 集成了 Babel，把 ts，js 转换为 amd js
1. 集成了 [MVC](https://github.com/ansiboy/node-web-server-mvc) 功能
1. 集成了 Less，Less 转 CSS
1. 提供了插件加载机制

## 安装使用

软件提供了 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](<(https://github.com/ansiboy/node-web-server)>)

**示例**

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

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

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

index.html 文件

```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
<html>
  <head></head>
  <body>
    <script src="./index.ts"></script>
  </body>
</html>
```

index.ts 文件

```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 可以看到

```js
'use strict'

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

## LESS 文件转换

文件夹如下

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

index.html 文件内容如下：

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

index.less 文件内容如下：

```less
@color: red;

h1 {
  color: @color;
}
```

运行命令

```
nwsp -d demo
```

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

<div style="color:red">Hello World</div>

## 动态脚本

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


**示例**

文件夹如下

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

hello-world.js 文件如下

```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
```

---
_Source: https://npm.io/package/maishu-node-mvc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
