ホームページ  >  記事  >  ウェブフロントエンド  >  Node.js で知っておく価値のある 18 の Web フレームワークとツールを共有することをお勧めします

Node.js で知っておく価値のある 18 の Web フレームワークとツールを共有することをお勧めします

青灯夜游
青灯夜游転載
2022-02-21 19:36:012698ブラウズ

この記事は、Web フレームワークとツールに関する共有記事です。この記事では、私が最も推奨する Node Web フレームワークとツール 18 個をまとめて共有します。皆さんのお役に立てれば幸いです。

Node.js で知っておく価値のある 18 の Web フレームワークとツールを共有することをお勧めします

Node.js は基盤となるプラットフォームです。開発者の作業をシンプルかつ効率的にするために、コミュニティは数千を超えるライブラリを作成しました。

時間が経つにつれて、誰もが選択できる優れたライブラリが数多く存在します。以下は不完全な選択リストです:

  • Express: Web サーバーを作成するための非常に簡単な方法を提供し、サーバーのコア機能に焦点を当てた、十分に強力で軽量です。

    // server.js
    const express = require('express')
    const app = express()
    const port = 3000
    
    app.get('/', (req, res) => {
      res.send('Hello World!')
    })
    
    app.listen(port, () => {
      console.log(`Example app listening on port ${port}`)
    })
  • koa: Express と同じチームによって構築されており、よりシンプルで小規模なライブラリを提供し、ES NEXT の非同期待機をサポートしています。構文。

    // server.js
    const Koa = require('koa');
    const app = new Koa();
    
    app.use(async ctx => {
      ctx.body = 'Hello World';
    });
    
    app.listen(3000);
  • NestJS: 効率的で信頼性が高く、スケーラブルなエンタープライズ グレードのサーバーサイドを構築するための TypeScript ベースの進歩的な Node.js フレームワーク応用。

    // app.controller.ts
    import { Get, Controller, Render } from '@nestjs/common';
    import { AppService } from './app.service';
    
    @Controller()
    export class AppController {
        constructor(private readonly appService: AppService) {}
    
        @Get()
        @Render('index')
        render() {
            const message = this.appService.getHello();
            return { message };
        }
    }
  • Egg.js: Node.js と Koa を使用して、より優れたエンタープライズ レベルのサーバー側フレームワークを構築します。

    // app/controller/home.js
    const Controller = require('egg').Controller;
    
    class HomeController extends Controller {
      async index() {
        this.ctx.body = 'Hello world';
      }
    }
    
    module.exports = HomeController;
  • Next.js: React このフレームワークは優れた開発エクスペリエンスを提供し、本番環境: サーバーサイドレンダリング、TypeScriptのサポート、ルートプリフェッチなど。

    // first-post.js
    export default function FirstPost() {
      return <h1>First Post</h1>
    }
  • #Remix: Remix は、構築のためのフロントエンドとバックエンドの両方を含むフルスタック Web フレームワークです。すぐに使える最新の Web アプリケーション。

    // index.tsx
    export async function loader({ request }) {
      return getProjects();
    }
    
    export async function action({ request }) {
      const form = await request.formData();
      return createProject({ title: form.get("title") });
    }
    
    export default function Projects() {
      const projects = useLoaderData();
      const { state } = useTransition();
      const busy = state === "submitting";
    
      return (
        <div>
          {projects.map((project) => (
            <Link to={project.slug}>{project.title}</Link>
          ))}
    
          <Form method="post">
            <input name="title" />
            <button type="submit" disabled={busy}>
              {busy ? "Creating..." : "Create New Project"}
            </button>
          </Form>
        </div>
      );
    }
  • Gatsby: React と GraphQL に基づいた静的サイト ジェネレーターで、非常に豊富なプラグインとエコシステムを備えています。

    // src/pages/index.js
    import * as React from &#39;react&#39;
    
    const IndexPage = () => {
      return (
        <main>
          <title>Home Page</title>
          <h1>Welcome to my Gatsby site!</h1>
          <p>I&#39;m making this by following the Gatsby Tutorial.</p>
        </main>
      )
    }
    
    export default IndexPage
  • hapi: Web アプリケーション サービスを構築するためのフレームワーク。開発者は構築に時間を費やすのではなく、再利用可能なアプリケーション ロジックの作成に集中できます。インフラストラクチャー。

    // index.js
    
    &#39;use strict&#39;;
    
    const Hapi = require(&#39;@hapi/hapi&#39;);
    
    const init = async () => {
    
        const server = Hapi.server({
            port: 3000,
            host: &#39;localhost&#39;
        });
    
        server.route({
            method: &#39;GET&#39;,
            path: &#39;/&#39;,
            handler: (request, h) => {
                return &#39;Hello World!&#39;;
            }
        });
    
        await server.start();
        console.log(&#39;Server running on %s&#39;, server.info.uri);
    };
    
    process.on(&#39;unhandledRejection&#39;, (err) => {
        console.log(err);
        process.exit(1);
    });
    
    init();
  • Fastify: 最小限のオーバーヘッドと強力なプラグイン アーキテクチャで最高の開発エクスペリエンスを提供することに重点を置いた Web フレームワーク。 Fastify は、最速の Node.js Web フレームワークの 1 つです。

    // server.js
    const fastify = require(&#39;fastify&#39;)({ logger: true })
    
    // Declare a route
    fastify.get(&#39;/&#39;, async (request, reply) => {
      return { hello: &#39;world&#39; }
    })
    
    // Run the server!
    const start = async () => {
      try {
        await fastify.listen(3000)
      } catch (err) {
        fastify.log.error(err)
        process.exit(1)
      }
    }
    start()
  • AdonisJS: 開発者のエクスペリエンスと安定性に細心の注意を払った、TypeScript に基づくフル機能のフレームワーク。 Adonis は、最速の Node.js Web フレームワークの 1 つです。

    // PostsController.js
    import Post from &#39;App/Models/Post&#39;
    
    export default class PostsController {
    
      public async index () {
        return Post.all()
      }
    
      public async store ({ request }) {
        return request.body()
      }
    
    }
  • FeatherJS: Feathers は、JavaScript または TypeScript を使用してリアルタイム アプリケーションと REST API を作成するための軽量 Web フレームワークです。プロトタイプを数分で構築し、エンタープライズグレードのアプリケーションを数日で構築します。

    // app.ts
    import feathers from &#39;@feathersjs/feathers&#39;;
    
    interface Message {
      id?: number;
      text: string;
    }
    
    
    class MessageService {
      messages: Message[] = [];
    
      async find () {
        return this.messages;
      }
    
      async create (data: Pick<Message, &#39;text&#39;>) {
        const message: Message = {
          id: this.messages.length,
          text: data.text
        }
    
        this.messages.push(message);
    
        return message;
      }
    }
    
    const app = feathers();
    
    app.use(&#39;messages&#39;, new MessageService());
    
    app.service(&#39;messages&#39;).on(&#39;created&#39;, (message: Message) => {
      console.log(&#39;A new message has been created&#39;, message);
    });
    
    const main = async () => {
      await app.service(&#39;messages&#39;).create({
        text: &#39;Hello Feathers&#39;
      });
    
      await app.service(&#39;messages&#39;).create({
        text: &#39;Hello again&#39;
      });
    
      const messages = await app.service(&#39;messages&#39;).find();
    
      console.log(&#39;All messages&#39;, messages);
    };
    
    main();
  • Loopback.io: 複雑な統合を備えた最新のアプリケーションの構築が容易になります。

    // hello.controller.ts
    import {get} from &#39;@loopback/rest&#39;;
    export class HelloController {
      @get(&#39;/hello&#39;)
      hello(): string {
        return &#39;Hello world!&#39;;
      }
    }
  • Meteor: クライアント側で JavaScript を使用してアプリケーションを構築する同型の方法を提供する非常に強力なフルスタック フレームワークサーバーとのコード。以前は既製ツールの完全なセットを提供していましたが、現在はフロントエンド ライブラリ React、Vue、Angular と統合されています。モバイル アプリケーションの作成にも使用できます。

  • Micro: 非同期 HTTP マイクロサービスを作成するための非常に軽量なサーバーを提供します。

    // index.js
    const https = require(&#39;https&#39;);
    const {run, send} = require(&#39;micro&#39;);
    
    const {key, cert, passphrase} = require(&#39;openssl-self-signed-certificate&#39;);
    
    const PORT = process.env.PORT || 3443;
    
    const options = {key, cert, passphrase};
    
    const microHttps = fn => https.createServer(options, (req, res) => run(req, res, fn));
    
    const server = microHttps(async (req, res) => {
        send(res, 200, {encrypted: req.client.encrypted});
    });
    
    server.listen(PORT);
    console.log(`Listening on https://localhost:${PORT}`);
  • Nx: 使用NestJS、Express、React、Angular等进行全栈monorepo开发的工具包,Nx有助于将您的开发从一个团队构建一个应用程序扩展到多个团队协作开发多个应用程序!

  • Sapper: Sapper是一个用于构建各种规模的Web应用程序框架,具有出色的开发体验和灵活的基于文件系统的路由,提供SSR等等。

  • Socket.io: 用于构建实时网络应用程序的WebSocket框架。

    // index.js
    const express = require(&#39;express&#39;);
    const app = express();
    const http = require(&#39;http&#39;);
    const server = http.createServer(app);
    const { Server } = require("socket.io");
    const io = new Server(server);
    
    app.get(&#39;/&#39;, (req, res) => {
      res.sendFile(__dirname + &#39;/index.html&#39;);
    });
    
    io.on(&#39;connection&#39;, (socket) => {
      console.log(&#39;a user connected&#39;);
    });
    
    server.listen(3000, () => {
      console.log(&#39;listening on *:3000&#39;);
    });
  • Strapi: Strapi是一种灵活的开源无头CMS,它让开发人员可以自由选择自己喜欢的工具和框架,同时允许编辑者轻松管理他们的内容。

以上就是我推荐的Node.js Web框架和工具,如果有更好的推荐欢迎在评论区评论。

更多node相关知识,请访问:nodejs 教程

以上がNode.js で知っておく価値のある 18 の Web フレームワークとツールを共有することをお勧めしますの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はjuejin.cnで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。