├── .gitignore ├── README.md ├── package.json └── src ├── routes └── main.routes.js └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .idea -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NodeJS Express ES6 Hello world 2 | 3 | > An example hello world app, showing how to build 4 | a REST API server using express.js and ES6 5 | and build for production 6 | 7 | ### Quick start 8 | 9 | ```bash 10 | # setup 11 | git clone https://github.com/500tech/nodejs-express-es6.git 12 | cd nodejs-express-es6 13 | npm install 14 | 15 | # start the server (starts babel-node with nodemon) 16 | npm start 17 | 18 | # open in browser 19 | http://localhost:3000 20 | 21 | # build for production (output to dist folder) 22 | npm run build 23 | 24 | ``` 25 | 26 | > Brought to you with love, from us at [500Tech](http://500Tech.com) - Israel's leading AngularJS consultancy 27 | 28 | ## License 29 | 30 | MIT Licensed 31 | 32 | Copyright (c) 2015, [500Tech](http://500tech.com) 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 35 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 36 | rights to use, copy, modify, merge, publish, distribute, sub-license, and/or sell copies of the Software, and to 37 | permit persons to whom the Software is furnished to do so, subject to the following conditions: 38 | 39 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 40 | Software. 41 | 42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 43 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 44 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 45 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build": "node_modules/babel/bin/babel.js src --source-maps --out-dir dist", 9 | "start": "node_modules/nodemon/bin/nodemon.js -- node_modules/babel/bin/babel-node.js src/server.js" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "express": "4.13.3" 15 | }, 16 | "devDependencies": { 17 | "babel": "5.8.29", 18 | "nodemon": "1.8.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/routes/main.routes.js: -------------------------------------------------------------------------------- 1 | // Import node module 2 | import express from 'express'; 3 | const router = express.Router(); 4 | 5 | // Arrow functions 6 | router.get('/', (req, res) => { 7 | res.send({message: 'Hello World!!'}); 8 | }); 9 | // Exporting an object as the default import for this module 10 | export default router; 11 | -------------------------------------------------------------------------------- /src/server.js: -------------------------------------------------------------------------------- 1 | // Importing node modules 2 | import express from 'express'; 3 | // Importing source files 4 | import routes from './routes/main.routes'; 5 | // consts 6 | const app = express(); 7 | 8 | app.use('/', routes); 9 | 10 | // arrow functions 11 | const server = app.listen(3000, () => { 12 | // destructuring 13 | const {address, port} = server.address(); 14 | 15 | // string interpolation: 16 | console.log(`Example app listening at http://${address}:${port}`); 17 | }); 18 | --------------------------------------------------------------------------------