imhazige / node-examples

examples of the nodejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Examples for Node.js

this example use three type of websocket server implementation

socket.io and sockjs are all implements a weird, arbitrary layer over the WebSocket protocol, which need server side support.

Server:

sockjs https://github.com/sockjs/sockjs-node
raw websocket server https://github.com/websockets/ws
socket.io https://github.com/socketio/socket.io (did not work, no error, no request if use path option, the api is not good)

Client(Node.js)

https://github.com/websockets/ws
Server connect to Echo test see http://websocket.org/echo.html

Client(Browser):

HTML5 https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/dev-guides/hh673567(v=vs.85) https://github.com/sockjs/sockjs-client
https://github.com/socketio/socket.io-client (the path option did not work)

https://stackoverflow.com/questions/5510537/websocket-library-for-browsers

Client:

develop:

use proxy to access express server
proxy also work with websocket protocol

How To Run

Server

npm run dev

Client

cd src/client
npm start

Server side rendering by nuxt.js associating with expressjs
using AdminLTE which depend on bootstrap@3 and jquery
create with templateexpress-template
it works much better than next.js and have better document for now. But..., still a tentative way to me. Have not much confidence to use it in real production.

problems:

  • the eslint --fix did not fix the error, so I ignore all the source in the .eslintignore

how to run

go the folder, run npm install then run npm run dev

Server side rendering by next.js associating with expressjs
using AdminLTE

The Problem

I have the problem as same as nextjs custom server build size is too big

  • after npm build, then npm start which with NODE_ENV = production, the main.js is still 1.2M, and there are hot reloading, it seems the production env did not work.
  • there are not much resource to find the answer to resolve the problem.

so for now, I will not update the example until there are more progress of the popularity of the next.

How to run

please see the shell run-dev.sh, change the environment variable in the shell then run from the meteor project folder bash ./run-dev.sh

Collections and pub/sub methods

subscribe to mongolist, render with react and Tracker.autorun.
use methods to update.

subscribe to mongolist, render with withtrack.
use methods to update.

subscribe to customer collection, which actually is a local collection

UI and theme

show how to use meteor accounts-password to login

show how to use meteor accounts-password to create a new user by email and password

show how use mongo dirver 3.1 api to do transaction, it will make the publication know the change, but there will be an obviously time gap and the meteor native collection will not affected by the transaction as they are in another database connection. NOTE:as transaction only work in a replica set(mongo 4.0). so will have error like Transaction numbers are only allowed on a replica set member when you run in local machine with one mongo node.

show how to apply theme layout of Material Dashboard, also show do logout of the account

Conclusion

tried local collection without mongodb, it will not publish the change across the connections as each collection is a local collection.

So, use mongodb if you using meteor, otherwise, most feature dispear!!!

problems:

func is not a function

see aldeed/meteor-collection2-core#30, just remove aldeed:simple-schema from .meteor/packages and .meteor/versions and import:
import SimpleSchema from 'simpl-schema'; instead

Recursion Solution - Trampoline

refer to this article

I add a promise case.

Run

go into folder es6-examples

npm i
npm start ./trampoline/recursion-single.js 

module cycle require

refer to this article ES modules: A cartoon deep-dive
but we should not mess our code up like such a require relation.

Run:

go into folder misc_examples\src\module_cycle_require

node .\m_a.js

This require conda to use nodejs11

Prepare Environment

conda create -n nodejs11 conda activate nodejs11 conda install -c conda-forge nodejs

Run

go into folder misc_examples\src\nodejs11

conda activate nodejs11
node .\brotli.js

Inspired by 10 lines implemention of hooks

A implementation of Reat Hooks

Also include implementation of Redux

Run

npm install
npm test

inspired by https://github.com/Akryum/apollo-server-example

inspired by https://github.com/Akryum/vue-apollo-example

copy from https://github.com/prisma-labs/nexus

copy from https://github.com/prisma/prisma-examples

copy from https://github.com/areslabs/alita

About

examples of the nodejs

License:MIT License


Languages

Language:JavaScript 51.6%Language:CSS 45.0%Language:Vue 1.4%Language:TypeScript 1.2%Language:HTML 0.3%Language:Objective-C 0.2%Language:Starlark 0.1%Language:Shell 0.1%Language:Java 0.1%Language:Dockerfile 0.0%