Skip to content

Instantly share code, notes, and snippets.

View barmgeat's full-sized avatar

Mustafa Hazim barmgeat

  • Berlin, Germany
View GitHub Profile
YouTube iframe:
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/videoseries?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG"
frameborder="0"
allow="autoplay; encrypted-media"
allowfullscreen>
</iframe>
function registerNeuUser(data){
userName = data.userName;
firstName = data.firstName;
lastName = data.lastName;
email = data.email;
password = data.password;
birthDay = data.birthDay;
//log the registered user
console.log('++++++++++ New-User +++++++++++++\n' +
const app = require('express')();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
const userFunctions = require('./userFunctions')
const hostname = '192.168.56.1';
const port = 3001;
io.on('connection', function (socket) {
console.log('a user connected');
var userSchema = mongoose.Schema({
"id": Number,
"username": String,
"paswod": String,
"name": String,
"last_name": String
});
var user = mongoose.model('users', userSchema);
@barmgeat
barmgeat / server.js
Last active June 27, 2019 16:30
connect to mongo database from node server
const mongoose = require('mongoose');
mongoose.connect(
'mongodb://username:password@host/databasename', {useNewUrlParser: true}
);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
const app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
const hostname = '192.168.56.1';
const port = 3001;
app.get('/', (req, res) =>{
res.sendFile(__dirname+'/server.html');
});
// in the controller.js handel the user reactions
module.export = function(app){
app.get('/AppName', function(req, res){
res.render('mainAppPage');
});
};
// in the views/mainAppPage.ejs
our html tamplate
// in the controller controller.js
module.export = function(app){
}
// in the app.js
var express = require('express');
var controller = require('./controller/controller.js');
..
// we need this module to create the server and handel the request from the user
const http = require('http');
// here is the host where the server will work
const hostname = '127.0.0.1';
// you can use any port but the likely for node.js is 3000
const port = 3000;
// here is a call back function we will talk about it later but this function called when the user requset the server URL
const server = http.createServer((req, res) => {
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});