{"id":22628086,"url":"https://github.com/logreg-n-coffee/nodejs-minimal-setup","last_synced_at":"2026-04-09T08:46:33.138Z","repository":{"id":43023974,"uuid":"510944713","full_name":"logreg-n-coffee/nodejs-minimal-setup","owner":"logreg-n-coffee","description":"Boilerplate for a Node.js application","archived":false,"fork":false,"pushed_at":"2022-07-29T22:04:39.000Z","size":111,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T08:13:29.471Z","etag":null,"topics":["javascript","mocha","nodejs","npm","testing"],"latest_commit_sha":null,"homepage":"http://hiruihu.com/nodejs-minimal-setup/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logreg-n-coffee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-06T01:16:55.000Z","updated_at":"2023-03-13T21:40:00.000Z","dependencies_parsed_at":"2022-09-09T09:01:29.502Z","dependency_job_id":null,"html_url":"https://github.com/logreg-n-coffee/nodejs-minimal-setup","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logreg-n-coffee%2Fnodejs-minimal-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logreg-n-coffee%2Fnodejs-minimal-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logreg-n-coffee%2Fnodejs-minimal-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logreg-n-coffee%2Fnodejs-minimal-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logreg-n-coffee","download_url":"https://codeload.github.com/logreg-n-coffee/nodejs-minimal-setup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246135736,"owners_count":20729056,"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":["javascript","mocha","nodejs","npm","testing"],"created_at":"2024-12-09T01:18:01.636Z","updated_at":"2026-04-09T08:46:28.073Z","avatar_url":"https://github.com/logreg-n-coffee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js Project Initialization\n\nIf there is no `node_modules/` directory in the root folder, run `npm install`.\n\nTo run the project, run:\n\n```bash\nnpm start\n```\n\nTo test the features, run:\n\n```bash\nnpm test\n```\n\n***\n\n## initialization\n\nIn the terminal environment, type the following command to initialize the project:\n\n```bash\nnpm init -y\n```\n\n-y shorthand flag: it should take all the defaults\n\n## configuration\n\n### package.json\n\nAfter initialization, the project folder should contain a file named `package.json`.\n\n```bash\nnpm config list\n\nnpm set init.author.name \"\u003cYour Name\u003e\"\nnpm set init.author.email \"you@example.com\"\nnpm set init.author.url \"example.com\"\nnpm set init.license \"MIT\"\n```\n\n### index.js\n\nIn the project's root folder, create a folder name `src`, and then in the `src` folder, create a file named `index.js`.\n\n```javascript\nconsole.log(\"node.js is running\");\n```\n\n### nodemon\n\nNodemon helps with creating an always-running node process. Use the following command to install the package nodemon:\n\n```bash\nnpm install nodemon --save-dev\n```\n\nNow package.json looks like this:\n\n```json5\n{\n  ...\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"start\": \"nodemon src/index.js\",\n    \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n  },\n  \"keywords\": [],\n  ...\n}\n```\n\n### Babel\n\nRecent JavaScript language features (ECMAScript) are not included in the recent Node.js versions. Babel helps to transpile the code into Vanilla JavaScript. To install Babel, simply run:\n\n```bash\nnpm install @babel/core @babel/node --save-dev\n```\n\nNext, add the npm start script to `package.json`:\n\n```json5\n{\n  ...\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"start\": \"nodemon --exec babel-node src/index.js\",\n    \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n  },\n  \"keywords\": [],\n  ...\n}\n```\n\nAfter editing the `package.json` file, add the preset to the application configuration.\n\n```bash\nnpm install @babel/preset-env --save-dev\n```\n\nIn the project's root directory, create a `.babelrc` file with the configuration:\n\n```json5\n{\n  \"presets\": [\n    \"@babel/preset-env\"\n  ]\n}\n```\n\n### dotenv\n\nIn the project's root directory, create a `.dotenv` file with any environmental variables:\n\n```bash\nMY_SECRET=hereismysecret\n```\n\nThen, in the terminal, install dotenv:\n\n```bash\nnpm install dotenv --save\n```\n\nImport dotenv into `src/index.js` to use environment variables:\n\n```javascript\nimport 'dotenv/config';\n\nconsole.log('nodemon src/index.js');\n\nconsole.log(process.env.MY_SECRET);\n```\n\n### Mocha and Chai for testing\n\nMocha will be our test runner which is responsible for encapsulating our tests in test suites (describe-block) and test cases (it-block). Chai will be our assertion library to run equality checks or other test related scenarios.\n\nTo install Mocha:\n\n```bash\nnpm install @babel/register --save-dev\n```\n\n```bash\nnpm install mocha --save-dev\n```\n\nThen, in the `package.json` file, include a test script:\n\n```json5\n{\n  ...\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"start\": \"nodemon --exec babel-node src/index.js\",\n    \"test\": \"mocha --require @babel/register 'src/**/**spec.js'\"\n  },\n  \"keywords\": [],\n  ...\n}\n```\n\nAs we use `**` in between, Mocha will run recursively through the src/ folder to find all files in the application.\n\nTo install Chai, run:\n\n```bash\nnpm install chai --save-dev\n```\n\nLater, we can specify the first test file `src/spec.js`:\n\n```javascript\nimport { expect } from 'chai';\n\ndescribe('true or false', () =\u003e {\n  it('true is true', () =\u003e {\n    expect(true).to.eql(true);\n  });\n\n  it('false is false', () =\u003e {\n    expect(false).to.eql(false);\n  });\n});\n```\n\nNote that there are other packages for testing, such as sinon.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogreg-n-coffee%2Fnodejs-minimal-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogreg-n-coffee%2Fnodejs-minimal-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogreg-n-coffee%2Fnodejs-minimal-setup/lists"}