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

ty-demo1-ty

v1.0.0

Published

```javascript !!app.js //引入模块 const express = require("express"); const app = express(); //引入路由 const LoginRouter = require("./server/login"); const RegisterRouter = require("./server/register"); const IndexRouter = require("./server/index"); //

Downloads

3

Readme

router login && register

 !!app.js
//引入模块
const express = require("express");
const app = express();
//引入路由
const LoginRouter = require("./server/login");
const RegisterRouter = require("./server/register");
const IndexRouter = require("./server/index");
//开启服务器
app.listen(8080, () => console.log("服务器在8080端口启动ing"));
//设置静态目录
app.use(express.static("public", {
    //设置默认页面
    index: "login.html"
}));
//处理json数据
app.use(express.json());
//调用路由
app.use(LoginRouter);
app.use(RegisterRouter);
app.use(IndexRouter);

!!server index.js
//引入模块
const fs = require("fs");
const express = require("express");
const router = express.Router();

//接受请求发送数据库的数据
router.get("/api/render", (req, res) => {
    res.send(JSON.parse(fs.readFileSync("mock/user.json")));
});
//抛出
module.exports = router;

!!server login.js
//引入模块
const fs = require("fs");
const express = require("express");
const router = express.Router();
//封装Promise异步读取方法
const FileRead = dirname => {
    return new Promise((resolve, rejects) => {
        fs.readFile(dirname, "utf-8", (err, data) => {
            if (err) {
                rejects(err);
                return;
            }
            resolve(JSON.parse(data));
        });
    });
}
//处理接口
router.post("/api/login", (req, res) => {
    let { username, password } = req.body;
    FileRead("mock/user.json").then(data => {
        //判断前端数据和数据库是否一致
        let flag = data.some(item => item.username === username && item.password === password);
        if (flag) {
            res.send({
                code: 1,
                mess: "登录成功"
            });
        } else {
            res.send({
                code: 0,
                mess: "用户名密码错误,请重新输入"
            });
        }
    });
});
//抛出
module.exports = router;

!!server register
//引入模块
const fs = require("fs");
const express = require("express");
const router = express.Router();
//封装Promise异步读取方法
const FileRead = dirname => {
    return new Promise((resolve, rejects) => {
        fs.readFile(dirname, "utf-8", (err, data) => {
            if (err) {
                rejects(err);
                return;
            }
            resolve(JSON.parse(data));
        });
    });
}
//处理接口
router.post("/api/register", (req, res) => {
    let { username, password } = req.body;
    FileRead("mock/user.json").then(data => {
        let flag = data.some(item => item.username === username);
        if (flag) {
            res.send({
                code: 0,
                mess: "用户名已存在,请重新输入"
            });
        } else {
            data.push(req.body);
            fs.writeFileSync("mock/user.json", JSON.stringify(data));
            res.send({
                code: 1,
                mess: "用户注册成功,请登录"
            });
        }
    });
});
//抛出
module.exports = router;

!!index.html
    <div class="homePage">
        <h2 class="title">欢迎xxx来到用户表单</h2>
        <ul class="list">
            <li>xxxxxx</li>
            <li>xxxxxx</li>
            <li>xxxxxx</li>
            <li>xxxxxx</li>
            <li>xxxxxx</li>
            <li>xxxxxx</li>
            <li>xxxxxx</li>
        </ul>
    </div>
    <script src="./js/axios.js"></script>
    <script>
        const $ = selector => typeof selector === "string" ? document.querySelector(selector) : selector;
        //获取本地存储的数据
        let user = localStorage.getItem("token");
        //渲染到标题里
        $(".title").innerHTML = `欢迎${user}来到用户表单`;
        //发送请求获取数据渲染到列表里
        axios.get("/api/render").then(result => {
            $(".list").innerHTML = result.data.map(item => {
                return ` <li>${item.username}</li>`;
            }).join("");
        });
    </script>

!!login.html
<div class="loginWrapper">
        <h2>欢迎来到网站博客</h2>
        <input type="text" placeholder="用户名" class="username">
        <input type="password" placeholder="密码" class="password">
        <button class="login">登录</button>
        <a href="./register.html">还没账号?去注册</a>
    </div>
    <script src="./js/axios.js"></script>
    <script>
        const $ = selector => typeof selector === "string" ? document.querySelector(selector) : selector;
        //给登录按钮添加点击事件
        $(".login").addEventListener("click", () => {
            //判断输入框里是否输入内容
            if ($(".username").value === "" && $(".password").value === "") {
                alert("请输入用户名密码");
                return;
            } else {
                //发送post请求
                axios.post("/api/login", {
                    username: $(".username").value,
                    password: $(".password").value
                }).then(result => {
                    let {
                        code,
                        mess
                    } = result.data;
                    if (code) {
                        alert(mess);
                        localStorage.setItem("token", $(".username").value);
                        location.href = "index.html";
                    } else {
                        alert(mess);
                    }
                });
            }
        });
    </script>

!!register.html
 <div class="registerWrapper">
        <h2>欢迎来到网站博客</h2>
        <input type="text" placeholder="用户名" class="username">
        <input type="password" placeholder="密码" class="password">
        <input type="text" placeholder="昵称" class="name">
        <button class="register">注册</button>
        <a href="./login.html">已有账号?去登录</a>
    </div>
    <script src="./js/axios.js"></script>
    <script>
        const $ = selector => typeof selector === "string" ? document.querySelector(selector) : selector;
        //给注册按钮添加点击事件
        $(".register").addEventListener("click", () => {
            //判断输入框里是否输入内容
            if ($(".username").value === "" && $(".password").value === "") {
                alert("请输入用户名密码");
                return;
            } else {
                //发送post请求
                axios.post("/api/register", {
                    username: $(".username").value,
                    password: $(".password").value
                }).then(result => {
                    let {code,mess } = result.data;
                    if (code) {
                        alert(mess);
                    } else {
                        alert(mess);
                    }
                });
            }
        });
    </script>