{"id":21017504,"url":"https://github.com/rootz491/nodejs-basics","last_synced_at":"2026-04-21T20:02:37.110Z","repository":{"id":40447967,"uuid":"363190731","full_name":"rootz491/nodeJs-basics","owner":"rootz491","description":"learning nodeJs at roof-top, ","archived":false,"fork":false,"pushed_at":"2023-03-07T01:15:45.000Z","size":9974,"stargazers_count":1,"open_issues_count":78,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-31T12:23:37.605Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","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/rootz491.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-04-30T15:58:00.000Z","updated_at":"2023-04-11T15:36:45.000Z","dependencies_parsed_at":"2023-02-17T02:32:01.047Z","dependency_job_id":null,"html_url":"https://github.com/rootz491/nodeJs-basics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rootz491/nodeJs-basics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootz491%2FnodeJs-basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootz491%2FnodeJs-basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootz491%2FnodeJs-basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootz491%2FnodeJs-basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rootz491","download_url":"https://codeload.github.com/rootz491/nodeJs-basics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootz491%2FnodeJs-basics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32108187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-19T10:19:38.882Z","updated_at":"2026-04-21T20:02:37.095Z","avatar_url":"https://github.com/rootz491.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"#   nodeJs\n\nintegrate with other tech like mongoose, Datastax and firebase and learning something cool.\n\n---\n\nNow that i've learned about nodeJs and various stuff within it.\n\nI'm now focusing on best way to deploy nodeJs web application. \n\n**Heroku** is still one of the best options, But i want something more flexible and controllable. that's where `Docker` comes in. \n\nSo let's learn docker.\n\n#\tdocker\n\nThere are two different things in the beginning:\n1. \timage\n2.\tcontainer\n\nsuppose i've created a simple node app. Now it's time to run, test and deploy it. First thing i'll do is to create a `Dockerfile`.\n\n###\tDockerfile\n\nit is set of commands that docker will execute in order to create docker image.\n\nsimple file can be:\n\n```sh\nFROM node \t#\tdocker will use latest node image to provide runtime env for app\n\nENV node_env production \t#\tsetting environment variable\n\nWORKDIR app/\t#\tcreate and enter folder `app` in container\n\nCOPY [ \"package.json\", \"package-lock.json*\", \"./\" ]\t#\tcopy package.json and package-lock.json file from current dir to folder named `/app` in continer\n\nRUN npm install\t#\tinstall all dependencies for node app by reading that package.json\n\nCOPY . .\t#\tcopy everything from local active dir to containers' active directory\n\nCMD [\"node\", \"app.js\"]\t#\tcommand that container executes everytime built image runs\n```\n#### key commands:\n\n*\t`FROM xyz`: use latest image of `xyz` from docker repo.\n\t*\talso `xyz:12.2.3` is an option, to use specific version of that image.\n\n*\t`RUN`:\tis to execute commands during building the image.\n\tyou can use multiple `RUN` in `Dockerfile`\n\t*\texample: `RUN npm install`\n\n*\t`CMD`:\tis command that execute in the container everytime you run a built image.\n\t*\texample: `CMD [\"node\", \"app.js\"]`\n\nthis file will give docker the instruction to a build an image.\n\n\u003e\tif there's some files on your local dir that you dont want to be on your container, then use `.dockerignore` file; it works exactly as `.gitignore` file.\n\n###\tBuild an image\n\nNow let's build an image:\n\n*\tgo to same directory as `Dockerfile` and execute following\n\n```sh\ndocker build --tag image-name .\n```\n\nthis command will create a docker image of name **image-name**\n\n*\tyou can list all docker images on your local machine using this command:\n\n```sh\ndocker images\n```\n\nnow that you've build your first image, you can find that image named **image-name** in this list.\n\n###\trunning our image\n\nIt's time to create a container by running that image.\n\n\n```sh\ndocker run image-name\n```\n\nthis command will run your image and will create a container with random name and **latest** tag.\n\nAnother thing to notice here is, containers are isolated from your local machine; means you can't access ports of container without exposing it to communicate with outside world.\n\n\n```sh\ndocker run -p 80:3000 --name something -d image-name\n```\n\nthis command will create a docker container named `todo` and run it.\n\n\n#### flags\n\n*\t`-p 80:3000`:\texposing container's port `3000` to local machine on port `80`\n\n*\t`-d`: dispatch means run in background.\n\n\nStart same container next time, \n```sh\ndocker start container-name\n``` \n\nStop a container\n```sh\ndocker stop container-name\n```\n\n----\n\n\nList of all running containers\n```sh\ndocker ps\n```\n\nList of all containers\n```sh\ndocker ps -a\n```\n\nLogs of continer\n```sh\ndocker logs container-name\n```\n\nContinous logs of container\n```sh\ndocker logs container-name -f\n```\n\nRemove a container\n```sh\ndocker rm container-name\n```\n\nremove an image\n```sh\ndocker rmi image-name\n```\n\n---\n\nchange tag of image \n```sh\ndocker tag image-name docker-id/image-name\n```\n\n\u003e\tthis will create an image alias to image `image-name`.\n\npush an image to dockerhub repository\n```sh\ndocker push docker-id/image-name\n```\n\npull any public image\n```sh\ndocker pull docker-id/image-name\n```\n\n---\n\n#\tcontainer as a database\n\nA container can be used as database like mySQL or mongodb;  \n\nBut the problem is, once you stop the container; all it's runtime data gets erased. \nTo overcome this problem, docker introduced the concept of **volumes**.\n\n###\tvolume \u0026 network\n\n`volume`: It's a persistent memory shared b/w containers and is located on your machine, managed by docker.\n`network`: It's user defined bridge newtwork that our application and database will use to talk to each other.\n\n---\n\nLet's setup mongodb database in a container with appropriate volumes to persist it's data over multiple runs;\n\n\n*\tcreate volumes\n\t*\twe'll create 2 volumes, one for data and other for configuration of MongoDB.\n\n```bash\n$ docker volume create mongodb\n$ docker volume create mongodb_config\n```\n\n*\tcreate network, It'll let our app and mongodb container talk to each other.\n\n```bash\n$ docker newtwork create mongodb\n```\n\n*\trun *MongoDB* in a container and attach to volumes and network that we've created above.\n\t*\tdocker will pull the image from hub and run it locally.\n\n```bash\n$ docker run -it --rm -d -v mongodb:/data/db \\\n  -v mongodb_config:/data/configdb \\\n  -p 26016:26016 \\\n  --network mongodb \\\n  --name mongodb \\\n  mongo\n```\n\n*\t\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootz491%2Fnodejs-basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frootz491%2Fnodejs-basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootz491%2Fnodejs-basics/lists"}