{"id":19573382,"url":"https://github.com/hiteshsahu/node-js-es6","last_synced_at":"2025-04-27T05:32:23.967Z","repository":{"id":46093037,"uuid":"304705944","full_name":"hiteshsahu/Node-JS-ES6","owner":"hiteshsahu","description":"Simple setup for using ES6 in Node JS server","archived":false,"fork":false,"pushed_at":"2020-10-16T23:10:04.000Z","size":65,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2023-03-02T04:37:23.497Z","etag":null,"topics":["babel-es6","es6-javascript","nodejs","nodejs-server","nodemon"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hiteshsahu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-16T18:17:18.000Z","updated_at":"2023-01-05T16:17:36.000Z","dependencies_parsed_at":"2022-07-19T00:17:08.656Z","dependency_job_id":null,"html_url":"https://github.com/hiteshsahu/Node-JS-ES6","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiteshsahu%2FNode-JS-ES6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiteshsahu%2FNode-JS-ES6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiteshsahu%2FNode-JS-ES6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiteshsahu%2FNode-JS-ES6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hiteshsahu","download_url":"https://codeload.github.com/hiteshsahu/Node-JS-ES6/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224061391,"owners_count":17249232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel-es6","es6-javascript","nodejs","nodejs-server","nodemon"],"created_at":"2024-11-11T06:33:34.925Z","updated_at":"2024-11-11T06:33:36.280Z","avatar_url":"https://github.com/hiteshsahu.png","language":"JavaScript","readme":"# Node JS With ES6\n\n#### Getting sarted:\nClone or Fork the project\n\u003e npm install\n\u003e\n\u003e npm run dev\n\n## How to Setup Node JS Server with [ES6](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes), [Babel](https://babeljs.io/docs/en/), \u0026 __[Nodemon](https://www.npmjs.com/package/nodemon)__\n\n        import NodeServer from \"./server/NodeServer\"\n        import ExpressServer from \"./server/ExpressServer\"\n        import dotenv from \"dotenv\"\n        dotenv.config()\n\n        // Start Node Server\n        const WebServer = new NodeServer();\n\n        //Start Express JS Server\n        const expressServer = new ExpressServer();\n\n\n--------------------------------------\n\n## Build Steps\n1. Install Node js and validate if [Node JS](https://nodejs.org/en/download/) is installed properly\n\u003e  __`node -v`__\n\n2. Create project directory and init Node package\n\u003e  __`mkdir nodeapp \u0026\u0026 cd nodeapp \u0026\u0026 npm init -y`__\n\n3. Create a **`src`** folder in your project's root directory to keep server code.\n\u003e __`mkdir src`__\n\n4. Create `Index.js` in **`src`** folder as starting point for Server\n\n## Set up Babel for precompiling ES6 into JavaScript\nBabel is a toolchain that is mainly used to convert `ECMAScript 2015+` code into a backwards compatible version of `JavaScript` in current and older browsers or environments.\n\n1. Install [Babel](https://babeljs.io/setup#installation)\n\u003e  __`npm install --save-dev @babel/core @babel/cli`__\n\n2. Install [Babel Preset](https://babeljs.io/docs/en/presets) \u0026 [Class Properties Plugin](https://babeljs.io/docs/en/babel-plugin-proposal-class-properties)\n\n\u003e __`npm install @babel/preset-env --save-dev`__ \u003cbr/\u003e\n\u003e __`npm install --save-dev @babel/plugin-proposal-class-properties`__\n\n__@babel/preset-env__ Allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!\n\n__@babel/plugin-proposal-class-properties__ transform **`ES6 class`** synthecic sugar into JavaScript `__Prototype__` \n\n\n3. Create **`.babelrc`** file in your project's root directory \u0026 add the following code in  **`.babelrc`** \n      \n        {\n        \"presets\": [\"@babel/preset-env\"],\n        \"plugins\": [\"@babel/plugin-proposal-class-properties\"] \n        }\n\n## Watch File change with Node Monitor\n\n1. Install __[Nodemon](https://www.npmjs.com/package/nodemon)__\n\u003e   __`npm i -d nodemon`__ \u003cbr/\u003e\n\u003e   __`npm install rimraf --save-dev`__\n\n_Nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected._\n\n2. Update __`package.json`__ by adding following line for precompiling ES6 and allowing nodemon to restart server when file changes\n\n```diff\n \"scripts\": {\n+ \"build\": \"babel src -d dist\"\n+ \"start\": \"npm run build \u0026\u0026 node dist\",\n+ \"restart\": \"rimraf dist \u0026\u0026 npm run start\",\n+ \"dev\": \"nodemon --exec npm run restart\"\n}\n```\n\n3. Create __`nodemon.json`__ file in your project's root directory\n\n4. Add src folder in watchlist by adding following code in __`nodemon.json`__\n\n        {\"watch\": [\"src\"]}\n\n## Finally Run the project\n \u003e __`npm run dev`__       \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiteshsahu%2Fnode-js-es6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhiteshsahu%2Fnode-js-es6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiteshsahu%2Fnode-js-es6/lists"}