“This is the 20th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

Node.js is an underlying platform. To make developers’ jobs easier and more efficient, the community has created more than a thousand libraries.

Over time, there are many excellent libraries to choose from. Here is a partial list:

  • Express: Provides a very simple way to create Web servers that are powerful enough and lightweight enough to focus on the core functionality of the server.

    // 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}`)})Copy the code
  • Koa: Built by the same team behind Express, it offers a simpler, smaller library and supports ES NEXT’s Async await syntax.

    // server.js
    const Koa = require('koa');
    const app = new Koa();
    
    app.use(async ctx => {
      ctx.body = 'Hello World';
    });
    
    app.listen(3000);
    Copy the code
  • NestJS: a typescript-based progressive Node.js framework for building efficient, reliable, and scalable enterprise-class server applications.

    // 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 }; }}Copy the code
  • Egg.js: Use Node.js and Koa to build a better enterprise-class server-side framework.

    // app/controller/home.js
    const Controller = require('egg').Controller;
    
    class HomeController extends Controller {
      async index() {
        this.ctx.body = 'Hello world'; }}module.exports = HomeController;
    Copy the code
  • Next. Js: The React framework provides a good development experience, providing all the functionality of a production environment: server-side rendering, TypeScript support, route prefetch, and more.

    // first-post.js
    export default function FirstPost() {
      return <h1>First Post</h1>
    }
    Copy the code
  • Remix: Remix is a full-stack Web framework that includes building a modern Web application front end and back end right out of the box.

    // 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>
      );
    }
    Copy the code
  • Gatsby: a static site generator based on React and GraphQL, with very rich plug-ins and ecology.

    // src/pages/index.js
    import * as React from 'react'
    
    const IndexPage = () = > {
      return (
        <main>
          <title>Home Page</title>
          <h1>Welcome to my Gatsby site!</h1>
          <p>I'm making this by following the Gatsby Tutorial.</p>
        </main>)}export default IndexPage
    Copy the code
  • Hapi: A framework for building Web application services that enables developers to focus on writing reusable application logic rather than spending time building infrastructure.

    // index.js
    
    'use strict';
    
    const Hapi = require('@hapi/hapi');
    
    const init = async() = > {const server = Hapi.server({
            port: 3000.host: 'localhost'
        });
    
        server.route({
            method: 'GET'.path: '/'.handler: (request, h) = > {
                return 'Hello World! '; }});await server.start();
        console.log('Server running on %s', server.info.uri);
    };
    
    process.on('unhandledRejection'.(err) = > {
        console.log(err);
        process.exit(1);
    });
    
    init();
    Copy the code
  • Fastify: A Web framework highly focused on providing the best development experience with minimal overhead and a powerful plug-in architecture. Fastify is one of the fastest Node.js Web frameworks.

    // server.js
    const fastify = require('fastify') ({logger: true })
    
    // Declare a route
    fastify.get('/'.async (request, reply) => {
      return { hello: 'world'}})// Run the server!
    const start = async() = > {try {
        await fastify.listen(3000)}catch (err) {
        fastify.log.error(err)
        process.exit(1)
      }
    }
    start()
    Copy the code
  • AdonisJS: A full-featured typescript-based framework that focuses heavily on developer experience and stability. Adonis is one of the fastest Node.js Web frameworks.

    // PostsController.js
    import Post from 'App/Models/Post'
    
    export default class PostsController {
    
      public async index () {
        return Post.all()
      }
    
      public async store ({ request }) {
        return request.body()
      }
    
    }
    Copy the code
  • FeatherJS: Feathers is a lightweight Web framework for creating real-time applications and REST apis using JavaScript or TypeScript. Build a prototype in minutes and an enterprise application in days.

    // app.ts
    import feathers from '@feathersjs/feathers'; interface Message { id? : number; text: string; }class MessageService {
      messages: Message[] = [];
    
      async find () {
        return this.messages;
      }
    
      async create (data: Pick<Message, 'text'>) {
        const message: Message = {
          id: this.messages.length,
          text: data.text
        }
    
        this.messages.push(message);
    
        returnmessage; }}const app = feathers();
    
    app.use('messages'.new MessageService());
    
    app.service('messages').on('created'.(message: Message) = > {
      console.log('A new message has been created', message);
    });
    
    const main = async() = > {await app.service('messages').create({
        text: 'Hello Feathers'
      });
    
      await app.service('messages').create({
        text: 'Hello again'
      });
    
      const messages = await app.service('messages').find();
    
      console.log('All messages', messages);
    };
    
    main();
    Copy the code
  • Loopback. IO: Makes it easier to build complex integrated modern applications.

    // hello.controller.ts
    import {get} from '@loopback/rest';
    export class HelloController {
      @get('/hello')
      hello(): string {
        return 'Hello world! '; }}Copy the code
  • Meteor: A very powerful full-stack framework that provides a homogeneous approach to building applications using JavaScript, sharing code on both the client and server sides. Previously a full set of off-the-shelf tools is now integrated with front-end libraries React, Vue, and Angular. It can also be used to create mobile applications.

  • Micro: It provides a very lightweight server to create exotic HTTP microservices.

    // index.js
    const https = require('https');
    const {run, send} = require('micro');
    
    const {key, cert, passphrase} = require('openssl-self-signed-certificate');
    
    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}`);
    Copy the code
  • Nx: A full-stack monorepo development kit using NestJS, Express, React, Angular, and more, Nx helps expand your development from one team building one application to multiple teams collaborating on multiple applications!

  • Sapper: Sapper is a framework for building Web applications of all sizes, with a great development experience and flexible file system-based routing, SSR, and more.

  • Socket. IO: WebSocket framework for building real-time web applications.

    // index.js
    const express = require('express');
    const app = express();
    const http = require('http');
    const server = http.createServer(app);
    const { Server } = require("socket.io");
    const io = new Server(server);
    
    app.get('/'.(req, res) = > {
      res.sendFile(__dirname + '/index.html');
    });
    
    io.on('connection'.(socket) = > {
      console.log('a user connected');
    });
    
    server.listen(3000.() = > {
      console.log('listening on *:3000');
    });
    Copy the code
  • Strapi: Strapi is a flexible open source headless CMS that gives developers the freedom to choose their favorite tools and frameworks, while allowing editors to easily manage their content.

These are my recommendations for node.js Web frameworks and tools. If you have better recommendations, feel free to comment in the comments section.

Welcome my public number [small handsome programming notes], so that they and others can harvest!