Initial commit

Initial project skeleton with a simple express server and a socket.io connection.

James Peret 7 ans auparavant
Commettre
80b1430b04
4 fichiers modifiés avec 44 ajouts et 0 suppressions
  1. 1 0
      .gitignore
  2. 8 0
      index.html
  3. 19 0
      index.js
  4. 16 0
      package.json

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
1
+/node_modules

+ 8 - 0
index.html

@@ -0,0 +1,8 @@
1
+<script src="/socket.io/socket.io.js"></script>
2
+<script>
3
+  var socket = io.connect('http://localhost:3100');
4
+  socket.on('news', function (data) {
5
+    console.log(data);
6
+    socket.emit('my other event', { my: 'data' });
7
+  });
8
+</script>

+ 19 - 0
index.js

@@ -0,0 +1,19 @@
1
+var winston = require('winston');
2
+var app = require('express')();
3
+var server = require('http').Server(app);
4
+var io = require('socket.io')(server);
5
+
6
+server.listen(3100, function () {
7
+  winston.info('Listening on port 3100');
8
+})
9
+
10
+app.get('/', function (req, res) {
11
+  res.sendFcile(__dirname + '/index.html');
12
+});
13
+
14
+io.on('connection', function (socket) {
15
+  socket.emit('news', { hello: 'world' });
16
+  socket.on('my other event', function (data) {
17
+    winston.info("Receiveid data", data);
18
+  });
19
+});

+ 16 - 0
package.json

@@ -0,0 +1,16 @@
1
+{
2
+  "name": "home-automation",
3
+  "version": "0.0.1",
4
+  "description": "Personal home automation system",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "test": "echo \"Error: no test specified\" && exit 1"
8
+  },
9
+  "author": "James Peret <james.peret@gmail.com> (http://jamesperet.com)",
10
+  "license": "ISC",
11
+  "dependencies": {
12
+    "express": "^4.15.4",
13
+    "socket.io": "^2.0.3",
14
+    "winston": "^2.3.1"
15
+  }
16
+}