Skip to content

Commit 8a419a7

Browse files
author
us͡an̸df͘rien͜ds͠
committed
Initial commit
0 parents  commit 8a419a7

File tree

15 files changed

+341
-0
lines changed

15 files changed

+341
-0
lines changed

.gitignore

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
### Linux
2+
*~
3+
.fuse_hidden*
4+
.directory
5+
.Trash-*
6+
.nfs*
7+
8+
### MacOS
9+
.DS_Store
10+
.AppleDouble
11+
.LSOverride
12+
Icon
13+
14+
._*
15+
.DocumentRevisions-V100
16+
.fseventsd
17+
.Spotlight-V100
18+
.TemporaryItems
19+
.Trashes
20+
.VolumeIcon.icns
21+
.com.apple.timemachine.donotpresent
22+
.AppleDB
23+
.AppleDesktop
24+
Network Trash Folder
25+
Temporary Items
26+
.apdisk
27+
28+
### Windows
29+
Thumbs.db
30+
ehthumbs.db
31+
ehthumbs_vista.db
32+
*.stackdump
33+
[Dd]esktop.ini
34+
$RECYCLE.BIN/
35+
*.cab
36+
*.msi
37+
*.msm
38+
*.msp
39+
*.lnk
40+
41+
### Node
42+
package-lock.json
43+
logs
44+
*.log
45+
npm-debug.log*
46+
yarn-debug.log*
47+
yarn-error.log*
48+
pids
49+
*.pid
50+
*.seed
51+
*.pid.lock
52+
lib-cov
53+
coverage
54+
.nyc_output
55+
.grunt
56+
bower_components
57+
.lock-wscript
58+
build/Release
59+
node_modules/
60+
jspm_packages/
61+
typings/
62+
.npm
63+
.eslintcache
64+
.node_repl_history
65+
*.tgz
66+
.yarn-integrity
67+
.env
68+
.next
69+
70+
### Docker
71+
Dockerfile
72+
docker-compose.yml

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm start

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# node-js-getting-started
2+
3+
A barebones Node.js app using [Express 4](http://expressjs.com/).
4+
5+
This application supports the [Getting Started with Node on Heroku](https://devcenter.heroku.com/articles/getting-started-with-nodejs) article - check it out.
6+
7+
## Running Locally
8+
9+
Make sure you have [Node.js](http://nodejs.org/) and the [Heroku CLI](https://cli.heroku.com/) installed.
10+
11+
```sh
12+
$ git clone [email protected]:heroku/node-js-getting-started.git # or clone your own fork
13+
$ cd node-js-getting-started
14+
$ npm install
15+
$ npm start
16+
```
17+
18+
Your app should now be running on [localhost:5000](http://localhost:5000/).
19+
20+
## Deploying to Heroku
21+
22+
```
23+
$ heroku create
24+
$ git push heroku master
25+
$ heroku open
26+
```
27+
or
28+
29+
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
30+
31+
## Documentation
32+
33+
For more information about using Node.js on Heroku, see these Dev Center articles:
34+
35+
- [Getting Started with Node.js on Heroku](https://devcenter.heroku.com/articles/getting-started-with-nodejs)
36+
- [Heroku Node.js Support](https://devcenter.heroku.com/articles/nodejs-support)
37+
- [Node.js on Heroku](https://devcenter.heroku.com/categories/nodejs)
38+
- [Best Practices for Node.js Development](https://devcenter.heroku.com/articles/node-best-practices)
39+
- [Using WebSockets on Heroku with Node.js](https://devcenter.heroku.com/articles/node-websockets)

app.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "Start on Heroku: Node.js with SCU ACM",
3+
"description": "A barebones Node.js app using Express 4",
4+
"repository": "https://github.com/SCUACM/node-tutorial",
5+
"logo": "https://cdn.rawgit.com/heroku/node-js-getting-started/master/public/node.svg",
6+
"keywords": ["scu", "acm", "node", "express", "heroku", "tutorial"],
7+
"image": "heroku/nodejs"
8+
}

lib/routes/api.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var router = require('express').Router()
2+
3+
router.route('/users')
4+
.get(function(req, res, next) {
5+
// return all active users
6+
});
7+
8+
// ...
9+
10+
module.exports = router

lib/routes/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var router = require('express').Router()
2+
3+
router.route('/')
4+
.get(function(req, res, next) {
5+
// Render index page
6+
7+
res.render('pages/index');
8+
});
9+
10+
router.route('/')
11+
12+
module.exports = router

lib/server.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var express = require('express')
2+
var path = require('path')
3+
var PORT = process.env.PORT || 5000
4+
5+
var app = express()
6+
var http = require('http').Server(app);
7+
8+
// Allow our 'public' directory to be viewable
9+
app.use(express.static(path.join(__dirname, '../public')))
10+
11+
// Set up our pages
12+
app.set('views', path.join(__dirname, '../views'))
13+
app.set('view engine', 'ejs')
14+
15+
// Set up routes
16+
app.use('/', require('./routes/index'))
17+
app.use('/api', require('./routes/api'))
18+
19+
// Set up socket.io
20+
var io = require('./socket-io')(http);
21+
22+
// Start your engines!
23+
http.listen(PORT, function() {
24+
console.log('Listening on %s', PORT)
25+
})

lib/socket-io.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// TODO:
2+
// Broadcast a message to connected users when someone connects or disconnects
3+
// Add support for nicknames
4+
// Don’t send the same message to the user that sent it himself. Instead, append the message directly as soon as he presses enter.
5+
// Add “{user} is typing” functionality
6+
// Show who’s online
7+
// Add private messaging
8+
// Share your improvements!
9+
10+
11+
module.exports = function(http) {
12+
var io = require('socket.io')(http);
13+
14+
io.on('connection', function(socket) {
15+
console.log('a user connected :)')
16+
17+
socket.on('message', function(msg) {
18+
io.emit('message', msg)
19+
})
20+
21+
socket.on('disconnect', function() {
22+
console.log('a user disconnected :(')
23+
})
24+
});
25+
26+
return io;
27+
}

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "node-tutorial",
3+
"version": "0.0.1",
4+
"description": "Node.js tutorial",
5+
"engines": {
6+
"node": "^8.9.4",
7+
"npm": "^5.6.0"
8+
},
9+
"main": "index.js",
10+
"scripts": {
11+
"start": "nodemon lib/server",
12+
"test": "true"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/SCUACM/node-tutorial"
17+
},
18+
"keywords": [
19+
"node",
20+
"heroku",
21+
"express",
22+
"scu",
23+
"acm",
24+
"tutorial"
25+
],
26+
"license": "MIT",
27+
"dependencies": {
28+
"ejs": "^2.5.7",
29+
"express": "^4.16.2",
30+
"socket.io": "^2.0.4"
31+
},
32+
"devDependencies": {
33+
"nodemon": "^1.14.12"
34+
}
35+
}

public/scripts/chat.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var socket = io();
2+
3+
socket.on('message', function(msg) {
4+
$('#messages').append('<li>' + msg + '</li>')
5+
})
6+
7+
$('form').submit(function() {
8+
socket.emit('message', $('#m').val());
9+
$('#m').val('');
10+
11+
return false;
12+
});

public/stylesheets/main.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* { margin: 0; padding: 0; box-sizing: border-box; }
2+
body { font: 13px Helvetica, Arial; }
3+
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
4+
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
5+
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
6+
#messages { list-style-type: none; margin: 0; padding: 0; }
7+
#messages li { padding: 5px 10px; }
8+
#messages li:nth-child(odd) { background: #eee; }

views/pages/index.ejs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<% include ../partials/header.ejs %>
5+
</head>
6+
<body>
7+
<ul id="messages"></ul>
8+
<form action="">
9+
<input id="m" autocomplete="off" /><button>Send</button>
10+
</form>
11+
12+
<script src="/scripts/chat.js"></script>
13+
</body>
14+
</html>

views/pages/users.ejs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<% include ../partials/header.ejs %>
5+
</head>
6+
<body>
7+
<% include ../partials/nav.ejs %>
8+
9+
<div class="container">
10+
<h2>Users:</h2>
11+
12+
<ul>
13+
<% users.forEach(function(u) { %>
14+
<li><%= u.id %> - <%= u.name %></li>
15+
<% }); %>
16+
</ul>
17+
</div>
18+
</body>
19+
</html>

views/partials/header.ejs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<title>Node.js Tutorial</title>
2+
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
3+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
4+
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
5+
<script src="/socket.io/socket.io.js"></script>
6+
<link rel="stylesheet" type="text/css" href="/stylesheets/main.css" />

views/partials/nav.ejs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<nav class="navbar navbar-default">
2+
<div class="container-fluid">
3+
<!-- Brand and toggle get grouped for better mobile display -->
4+
<div class="navbar-header">
5+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
6+
<span class="sr-only">Toggle navigation</span>
7+
<span class="icon-bar"></span>
8+
<span class="icon-bar"></span>
9+
<span class="icon-bar"></span>
10+
</button>
11+
<a class="navbar-brand" href="#">Brand</a>
12+
</div>
13+
14+
<!-- Collect the nav links, forms, and other content for toggling -->
15+
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
16+
<ul class="nav navbar-nav">
17+
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
18+
<li><a href="#">Link</a></li>
19+
<li class="dropdown">
20+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
21+
<ul class="dropdown-menu">
22+
<li><a href="#">Action</a></li>
23+
<li><a href="#">Another action</a></li>
24+
<li><a href="#">Something else here</a></li>
25+
<li role="separator" class="divider"></li>
26+
<li><a href="#">Separated link</a></li>
27+
<li role="separator" class="divider"></li>
28+
<li><a href="#">One more separated link</a></li>
29+
</ul>
30+
</li>
31+
</ul>
32+
<form class="navbar-form navbar-left">
33+
<div class="form-group">
34+
<input type="text" class="form-control" placeholder="Search">
35+
</div>
36+
<button type="submit" class="btn btn-default">Submit</button>
37+
</form>
38+
<ul class="nav navbar-nav navbar-right">
39+
<li><a href="#">Link</a></li>
40+
<li class="dropdown">
41+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
42+
<ul class="dropdown-menu">
43+
<li><a href="#">Action</a></li>
44+
<li><a href="#">Another action</a></li>
45+
<li><a href="#">Something else here</a></li>
46+
<li role="separator" class="divider"></li>
47+
<li><a href="#">Separated link</a></li>
48+
</ul>
49+
</li>
50+
</ul>
51+
</div><!-- /.navbar-collapse -->
52+
</div><!-- /.container-fluid -->
53+
</nav>

0 commit comments

Comments
 (0)