├── Procfile ├── public ├── lang-logo.png ├── stylesheets │ └── main.css └── node.svg ├── views ├── pages │ ├── index.ejs │ └── db.ejs └── partials │ ├── header.ejs │ └── nav.ejs ├── .gitignore ├── app.json ├── package.json ├── test.js ├── README.md └── index.js /Procfile: -------------------------------------------------------------------------------- 1 | web: node index.js 2 | -------------------------------------------------------------------------------- /public/lang-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skyme5/node-js-getting-started/master/public/lang-logo.png -------------------------------------------------------------------------------- /views/pages/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node build artifacts 2 | node_modules 3 | npm-debug.log 4 | 5 | # Local development 6 | *.env 7 | *.dev 8 | .DS_Store 9 | 10 | # Docker 11 | Dockerfile 12 | docker-compose.yml 13 | package-lock.json 14 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Start on Heroku: Node.js", 3 | "description": "A barebones Node.js app using Express 4", 4 | "repository": "https://github.com/heroku/node-js-getting-started", 5 | "logo": "https://cdn.rawgit.com/heroku/node-js-getting-started/master/public/node.svg", 6 | "keywords": ["node", "express", "heroku"], 7 | "image": "heroku/nodejs" 8 | } 9 | -------------------------------------------------------------------------------- /views/pages/db.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <% include ../partials/header.ejs %> 5 | 6 | 7 | 8 | 9 | <% include ../partials/nav.ejs %> 10 | 11 |
12 |

Database Results

13 | 14 | 19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /views/partials/header.ejs: -------------------------------------------------------------------------------- 1 | Node.js Getting Started on Heroku 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /public/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | .jumbotron { 2 | background: #532F8C; 3 | color: white; 4 | padding-bottom: 80px; } 5 | .jumbotron .btn-primary { 6 | background: #845ac7; 7 | border-color: #845ac7; } 8 | .jumbotron .btn-primary:hover { 9 | background: #7646c1; } 10 | .jumbotron p { 11 | color: #d9ccee; 12 | max-width: 75%; 13 | margin: 1em auto 2em; } 14 | .navbar + .jumbotron { 15 | margin-top: -20px; } 16 | .jumbotron .lang-logo { 17 | display: block; 18 | background: #B01302; 19 | border-radius: 50%; 20 | overflow: hidden; 21 | width: 100px; 22 | height: 100px; 23 | margin: auto; 24 | border: 2px solid white; } 25 | .jumbotron .lang-logo img { 26 | max-width: 100%; } 27 | 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-js-getting-started", 3 | "version": "0.3.0", 4 | "description": "A sample Node.js app using Express 4", 5 | "engines": { 6 | "node": "12.x" 7 | }, 8 | "main": "index.js", 9 | "scripts": { 10 | "start": "node index.js", 11 | "test": "node test.js" 12 | }, 13 | "dependencies": { 14 | "ejs": "^2.5.6", 15 | "express": "^4.15.2", 16 | "request": "^2.88.0", 17 | "simple-socks": "^1.0.3" 18 | }, 19 | "devDependencies": { 20 | "tape": "^4.7.0" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/skyme5/node-js-getting-started" 25 | }, 26 | "keywords": [ 27 | "node", 28 | "heroku", 29 | "express" 30 | ], 31 | "license": "MIT" 32 | } 33 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | const { spawn } = require('child_process'); 2 | const request = require('request'); 3 | const test = require('tape'); 4 | 5 | // Start the app 6 | const env = Object.assign({}, process.env, {PORT: 5000}); 7 | const child = spawn('node', ['index.js'], {env}); 8 | 9 | test('responds to requests', (t) => { 10 | t.plan(4); 11 | 12 | // Wait until the server is ready 13 | child.stdout.on('data', _ => { 14 | // Make a request to our app 15 | request('http://127.0.0.1:5000', (error, response, body) => { 16 | // stop the server 17 | child.kill(); 18 | 19 | // No error 20 | t.false(error); 21 | // Successful response 22 | t.equal(response.statusCode, 200); 23 | // Assert content checks 24 | t.notEqual(body.indexOf("Node.js Getting Started on Heroku"), -1); 25 | t.notEqual(body.indexOf("Getting Started with Node on Heroku"), -1); 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 https://github.com/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) 40 | -------------------------------------------------------------------------------- /public/node.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 12 | 17 | 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const path = require('path') 3 | const request = require('request') 4 | const PORT = process.env.PORT || 5000 5 | const 6 | socks5 = require('simple-socks'), 7 | server = socks5.createServer().listen(PORT, () => console.log(`Listening on ${ PORT }`)); 8 | 9 | 10 | // function get(url) { 11 | // return new Promise((resolve, reject) => { 12 | // request(url, function (error, response, body) { 13 | // if (error) { 14 | // reject(error) 15 | // return 16 | // } 17 | // resolve(body) 18 | // }) 19 | // }) 20 | // } 21 | 22 | // express() 23 | // .use(express.static(path.join(__dirname, 'public'))) 24 | // .set('views', path.join(__dirname, 'views')) 25 | // .set('view engine', 'ejs') 26 | // .get('/app', (req, res) => { 27 | // get(req.query.url).then((response) => { 28 | // res.send(response) 29 | // }).catch((err)=>{ 30 | // res.send(err) 31 | // }) 32 | // }) 33 | // .listen(PORT, () => console.log(`Listening on ${ PORT }`)) 34 | 35 | // When a reqest arrives for a remote destination 36 | server.on('proxyConnect', function (info, destination) { 37 | console.log('connected to remote server at %s:%d', info); 38 | }); 39 | 40 | // When data arrives from the remote connection 41 | // server.on('proxyData', function (data) { 42 | // console.log(data.length); 43 | // }); 44 | 45 | // When an error occurs connecting to remote destination 46 | server.on('proxyError', function (err) { 47 | console.error('unable to connect to remote server'); 48 | console.error(err); 49 | }); 50 | 51 | // When a proxy connection ends 52 | server.on('proxyEnd', function (response, args) { 53 | console.log('socket closed with code %d', response); 54 | console.log(args); 55 | }); 56 | -------------------------------------------------------------------------------- /views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 | 34 | --------------------------------------------------------------------------------