examples of the nodejs
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
meteor
misc_examples
nextjs_express
nuxt_express
websocket
.gitignore
LICENSE
README.md
nuxt-admin-lte.png

README.md

Examples for Node.js

Websocket Example

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  

Nuxt with Expressjs

Server side rendering by next.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

Next.js with Expressjs

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 eresolve the problem.

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

Meteor Examples

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

pubsub1

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

pubsub2

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

pubsub3

subscribe to customer collection, which actually is a local collection

UI and theme

login

show how to use meteor accounts-password to login

newuser

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

transaction

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.

dashboard

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 https://github.com/aldeed/meteor-collection2-core/issues/30, just remove aldeed:simple-schema from .meteor/packages and .meteor/versions and import:
import SimpleSchema from 'simpl-schema'; instead

Miscellaneous Examples

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