Examples of servers constructed with node.js from scratch and with the framework express.
It consists of differents examples:
Server constructed from scratch, it displays Hello World
More elaborated server constructed from scratch which render html pages if exists, and sends HTTP answers if it doesn't.
Server constructed with express. It shows a Hello World messege.
Server constructed with express which render the HTML pages stored in ./public folder.
Serves differenths methods like POST, GET, PUT, DELETE.
You can use the extension of Chrome: POSTMan
It is a improve of server-5.js using the Router object.
Is the assignment1, where I implemented rounting requiring it from the principal module.
node <name of the server>
Is a server constructed with express-generator. It serves the same of server-7.js.
sudo npm install express-generator -g
express node-express-gen
npm install
npm start
Is a server using simple connection with mongoDB.
npm install express morgan body-parser
node server-number.js
Server that inserts, modify and consults in a collection of a DB.
npm install mongodb --save
npm install assert --save
node server-number.js
Starting with mongoose and the definitions of Schemas mongodb. server1.js and server2.js do the same with different methods. server3.js uses an document inside another with Schemas.
npm install
node server-number.js
Server that handles some operations with users, using mongoose.
npm install
npm run start
Basic authorization to access to the server.
npm install
node server-1.js
Basic authorization to access to the server and quick start with cookies and signed cookies.
npm install
node server-2.js
Basic authorization to access to the server using express sessions.
npm install
node server-3.js
Authentication using passport and JSON Web Tokens (JWB).
npm install
npm run start
Here you can see how to reference documents with mongoose population. This server has users authentication.
npm install
npm run start
Example of a server that uses https and redirects the traffic to it.
npm install
npm run start
openssl genrsa 1024 > private.key
openssl req -new -key private.key -out cert.csr
openssl x509 -req -in cert.csr -signkey private.key -out certificate.pem
See an example here.
Authenticating users with Facebook using OAuth and passport-facebook.
You have to register your app in facebook developers and update the clientID
with the identification of the app and the clientSecret for the secret application password provided by Facebook in
our server and
to run the server.
You also need to indicate in the configuration of the app in facebook the callbackURL
that you are using when the user login successfuly with the app.
npm install
npm run start
See another example here and here.
You can also make authentications with Twitter using passport-twitter, with Google using passport-google-oauth.
Server using LoopBack.
npm install
node .
In the servers that uses mongoDB remember to run the mongo daemon before running the server. You can check it here.
See and learn more at: