# njserver

> Nodejs webserver

Latest version **1.5.7** (published 2019-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install njserver
pnpm add njserver
yarn add njserver
bun add njserver
```

Provides the command `njserver`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.7 |
| Published | 2019-08-29 |
| First published | 2019-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 110.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | flynn |
| Maintainers | verup |
| Keywords | web, njserver, webserver, server, api, restful, http, https, http2, ssl |

## Links

- npm: https://www.npmjs.com/package/njserver
- Repository: https://gitee.com/gookee/njserver
- npm.io page: https://npm.io/package/njserver

## Dependencies (12)

- [cron](https://npm.io/package/cron.md) latest
- [uuid](https://npm.io/package/uuid.md) latest
- [vary](https://npm.io/package/vary.md) latest
- [bytes](https://npm.io/package/bytes.md) latest
- [mssql](https://npm.io/package/mssql.md) latest
- [mysql](https://npm.io/package/mysql.md) latest
- [log4js](https://npm.io/package/log4js.md) latest
- [accepts](https://npm.io/package/accepts.md) latest
- [formidable](https://npm.io/package/formidable.md) latest
- [on-headers](https://npm.io/package/on-headers.md) latest
- [safe-buffer](https://npm.io/package/safe-buffer.md) latest
- [compressible](https://npm.io/package/compressible.md) latest

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.5.7 (latest) — 2019-08-29
- 1.5.1 — 2019-08-16
- 1.4.10 — 2019-08-08
- 1.4.9 — 2019-08-05
- 1.4.8 — 2019-08-01
- 1.3.9 — 2019-07-26
- 1.3.3 — 2019-07-24
- 1.3.2 — 2019-07-15
- 1.3.0 — 2019-07-15
- 1.2.10 — 2019-07-01
- 1.2.9 — 2019-06-21

## README

# njserver

## 安装njserver

> npm install njserver

## njserver命令

* 初始化项目文件：npm njserver init
* 更新项目文件：npm njserver update
* 启动njserver程序：npm njserver start

## 启动njserver

```javascript
var njserver = require('njserver');

njserver.use('/', './assets/');

njserver.use('/', {
    dir: './controller/'
});

njserver.use('/', {
    before: function (req, res, next) {
        require('./interceptor/access')(req, res, next);
    },

    after: function (req, res, chunk, next) {
        require('./interceptor/content')(req, res, chunk, next);
    }
});

njserver.listen();
```

## config.js配置文件示例

```JavaScript
global.sysConfig = {
    serverName: 'test', //应用名称
    serverDescription: '测试系统', //应用描述
    isDebug: true, //是否调试模式
    servers: [{ //监听协议及端口
            protocol: 'http',
            port: 8081
        },
        {
            protocol: 'https',
            port: 443,
            key: '94xh.com.key',
            cert: '94xh.com.pem'
        },
        {
            protocol: 'http2',
            port: 8082,
            key: '94xh.com.key',
            cert: '94xh.com.pem'
        }
    ],
    session: {
        timeout: 1800000, //session过期时间，单位ms，默认30min
        store: 'mysql', //session存储介质，默认为空使用内存存储，可设置数据库类型：mysql
        table: 'sessions' //存储在数据库中的表名称，结构：`njsid` varchar(255) 主键 && `session` json && `update` datetime(0)
    },
    sessionClearTime: '0 */30 * * * *', //每30分钟清理一次过期session
    requestTimeout: 120000, //request请求超时时间，单位ms，默认120s
    responseTimeout: 120000, //response响应超时时间，单位ms，默认120s
    fileCacheControl: 'max-age=7200', //静态文件客户端缓存配置，默认2h过期
    page404: '', //自定义404页面路径，默认不设置为空
    page500: '', //自定义500页面路径，默认不设置为空
    mysql: { //mysql数据库连接配置
        host: '127.0.0.1', //mysql数据库主机
        user: 'root', //mysql数据库用户名
        password: '123456', //mysql数据库密码
        database: 'test', //mysql数据库名称
        supportBigNumbers: true, //处理大数字（BIGINT和DECIMAL）时需要启动此项
        bigNumberStrings: true, //使用supportbignumbers和bignumberstrings时总是返回JavaScript字符串对象
        multipleStatements: true, //mysql数据库查询是否支持多条语句
        connectionLimit: 10, //mysql连接池创建的最大连接数
        connectTimeout: 10000, //mysql连接超时时间，单位ms，默认10s
        acquireTimeout: 10000, //mysql从连接池中获取连接超时时间，单位ms，默认10s
        timeout: 60000, //mysql查询超时时间，单位ms，默认10s
        timezone: '08:00' //mysql时区设置
    },
    mssql: { //mssql数据库连接配置
        server: '127.0.0.1', //mssql数据库主机
        user: 'sa', //mssql数据库用户名
        password: '123456', //mssql数据库密码
        database: 'test', //mssql数据库名称
        connectionTimeout: 15000, //mssql连接超时时间，单位ms，默认15s
        requestTimeout: 600000, //mssql查询超时时间，单位ms，默认15s
        parseJSON: true, //将json数据集转化成json对象
        multipleStatements: true, //mssql数据库查询是否支持多条语句
        pool: {
            max: 10, //mssql连接池创建的最大连接数
            acquireTimeoutMillis: 10000, //mysql从连接池中获取连接超时时间，单位ms，默认不限制
            idleTimeoutMillis: 30000 //mssq连接池空闲连接保持时间，单位ms，默认30s
        }
    },
    tableRoute: { //数据库名称加密映射
        '0000000x': 'dw_log'
    },
    mail: {
        service: 'QQex',
        auth: {
            user: 'test@qq.com',
            pass: '123456'
        }
    },
    mime: { //服务器支持的MIME类型
        css: 'text/css',
        gif: 'image/gif',
        html: 'text/html',
        htm: 'text/html',
        ico: 'image/x-icon',
        jpeg: 'image/jpeg',
        jpg: 'image/jpeg',
        js: 'text/javascript',
        json: 'application/json',
        pdf: 'application/pdf',
        png: 'image/png',
        svg: 'image/svg+xml',
        swf: 'application/x-shockwave-flash',
        tiff: 'image/tiff',
        txt: 'text/plain',
        woff: 'application/font-woff',
        woff2: 'application/font-woff',
        ttf: 'application/octet-stream',
        wav: 'audio/x-wav',
        wma: 'audio/x-ms-wma',
        wmv: 'video/x-ms-wmv',
        xml: 'text/xml',
        exe: 'application/octet-stream',
        docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        doc:'application/msword',
        xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        xls:'application/vnd.ms-excel',
        zip: 'application/zip',
        rar:' application/octet-stream',
        mp4: 'video/mp4 application/octet-stream',
        ppt:'application/vnd.ms-powerpoint',
        pptx:'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        mp3:'audio/mpeg',
        bmp:'image/bmp'
    },
    uploadType: ['gif', 'jpg', 'png', 'bmp', 'xls', 'xlsx', 'doc', 'docx', 'ppt', 'pptx', 'pdf', 'zip', 'rar', 'txt'], //允许上传文件的格式
    uploadTemp: './tmp', //上传文件的临时保存路径
    uploadMaxFieldsSize: 10485760, //允许POST参数大小，单位byte，默认10mb
    uploadMaxFields: 1000, //允许POST参数数量
    uploadMaxFileSize: 104857600, //允许上传文件的大小，单位byte，默认100mb
    downloadBufferSize: 1048576, //下载文件块大小，单位byte，默认1mb
    downloadFileSize: 104857600, //允许下载文件的大小，单位byte，默认100mb
    log4js: { //日志配置
        appenders: {
            'rule-console': { //控制台打印
                type: 'console'
            },
            'rule-access': { //用户访问记录
                type: 'dateFile',
                filename: './logs/access/acc.log',
                encoding: 'utf-8',
                pattern: 'yyyy-MM-dd',
                daysToKeep: 30,
                keepFileExt: true,
                alwaysIncludePattern: true
            },
            'rule-system': { //服务器日志记录
                type: 'dateFile',
                filename: './logs/system/sys.log',
                encoding: 'utf-8',
                pattern: 'yyyy-MM-dd',
                daysToKeep: 30,
                keepFileExt: true,
                alwaysIncludePattern: true
            }
        },
        categories: {
            default: {
                appenders: ['rule-console', 'rule-system'],
                level: 'debug' //服务器日志记录级别
            },
            access: {
                'appenders': ['rule-access'],
                'level': 'info' //服务器日志记录级别
            }
        },
        pm2: true, //使用pm2启动应用
        disableClustering: true //每个进程单独记录日志
    }
};
```

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