{"id":18421130,"url":"https://github.com/akarsh/osmtogeojson-nodejs-server-tutorial","last_synced_at":"2026-03-16T13:04:06.895Z","repository":{"id":159217582,"uuid":"99404263","full_name":"akarsh/osmtogeojson-nodejs-server-tutorial","owner":"akarsh","description":"Tutorial for osmtogeojson-nodejs-server.","archived":false,"fork":false,"pushed_at":"2024-09-10T20:57:51.000Z","size":429,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T19:45:00.744Z","etag":null,"topics":["curl","geojson","javascript","localhost","nodejs","openstreetmap","openstreetmap-data","tutorial","wget"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akarsh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-05T06:34:15.000Z","updated_at":"2023-10-17T11:38:21.000Z","dependencies_parsed_at":"2024-12-24T18:13:43.327Z","dependency_job_id":"c084e7e0-add3-4c98-bbc2-a6cca644a2be","html_url":"https://github.com/akarsh/osmtogeojson-nodejs-server-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/akarsh/osmtogeojson-nodejs-server-tutorial","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2Fosmtogeojson-nodejs-server-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2Fosmtogeojson-nodejs-server-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2Fosmtogeojson-nodejs-server-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2Fosmtogeojson-nodejs-server-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akarsh","download_url":"https://codeload.github.com/akarsh/osmtogeojson-nodejs-server-tutorial/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2Fosmtogeojson-nodejs-server-tutorial/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272299326,"owners_count":24909635,"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","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["curl","geojson","javascript","localhost","nodejs","openstreetmap","openstreetmap-data","tutorial","wget"],"created_at":"2024-11-06T04:24:28.093Z","updated_at":"2025-12-24T13:24:54.214Z","avatar_url":"https://github.com/akarsh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n# osmtogeojson-nodejs-server-tutorial\nTutorial for osmtogeojson-nodejs-server.\n\n## Table of Contents\n- [Introduction](#introduction)\n- [Tutorial](#tutorial)\n- [Credits](#credits)\n\n### Introduction\nIn this tutorial you will be able to learn how to download an osm file from the OpenStreetMap-website via api using wget and curl.\n\nI created this tutorial because i faced some difficulties in implemntation of osmtogeojson nodejs library. As, the osm file has to be parsed using xmldom parser and then again using JSON.stringify to save the parsed file as GeoJSON.\n\n### Tutorial\nThe library files are declared\n```\nvar osmtogeojson = require('osmtogeojson');  // osmtogeojson library\nvar DOMParser = require('xmldom').DOMParser; // xmldom parser library\nvar path = process.cwd();                    // accessing the current directory\nvar fs = require('fs');                      // fs library\nvar url = require('url');                    // url library\nvar exec = require('child_process').exec;\nvar spawn = require('child_process').spawn;\nvar connect = require('connect');            // connect library\nvar serveStatic = require('serve-static');   // serve-static library\n```\n\nYou need to provide the boundingbox coordinates of the osm file to be downloaded from the osm api\n```\n/* file url - contains coordinates of the bounding box of osm file to be download */\nvar new_file_url = 'http://api.OpenStreetMap.org/api/0.6/map?bbox=11.54,48.14,11.543,48.145';\n```\nIf you are using local-server of [OpenStreetMap-website](https://github.com/OpenStreetMap/OpenStreetMap-website). Then the new_file_url will be\n```\nvar new_file_url = 'http://localhost:3000/api/0.6/map?bbox=11.54,48.14,11.543,48.145';\n```\n\nYou can initially test your nodejs-sever for osmtogeojson by downloading the osm and GeoJSON file locally.\n```\n/* Converting and saving files locally */\n// fs.readFile(path + \"//testmap.osm\", function(err, data)\n// {\n//     if(err)\n//         console.log(err)\n//     else\n//     \tvar docNew = new DOMParser().parseFromString(data.toString());\n//        \tvar newdocNew = osmtogeojson(docNew);\n//         fs.writeFile(path + \"//testmap.geojson\", JSON.stringify(newdocNew), function(err)\n// \t\t{\n//     \t\tif(err)\n//        \t\t\tconsole.log(err);\n//     \t\telse\n//        \t\t \tconsole.log('file is created');\n// \t\t});\n// });\n```\n\nDownloading the osm file via wget\n```\n/* download osm file using wget */\nvar download_file_wget = function(file_url) {\n    // compose the wget command\n    var wget = 'wget -O ' + '\"' + path + '/map.osm' + '\"' + ' ' + file_url;\n    console.log(wget);\n    // excute wget using child_process' exec function\n    var child = exec(wget, function(err, stdout, stderr) {\n        if (err)\n          throw err;\n        else\n          console.log(' downloaded to ' + path);\n    });\n};\n\n/* calling the  download_file_wget function*/\ndownload_file_wget(new_file_url);\n```\n\nDownloading the osm file via curl\n```\n/* download osm file using curl */\nvar download_file_curl = function(file_url) {\n    // create an instance of writable stream\n    var file = fs.createWriteStream('' + path + '/map.geojson' + '');\n    // execute curl using child_process' spawn function\n    var curl = spawn('curl', [file_url]);\n    // add a 'data' event listener for the spawn instance\n    curl.stdout.on('data', function(data) {\n      var docNew = new DOMParser().parseFromString(data.toString());\n      var newdocNew = osmtogeojson(docNew);\n      file.write(JSON.stringify(newdocNew));\n    });\n    // add an 'end' event listener to close the writeable stream\n    curl.stdout.on('end', function(data) {\n        file.end();\n        console.log(' downloaded to ' + '' + path + '/map.geojson' + '');\n    });\n    // when the spawn child process exits, check if there were any errors and close the writeable stream\n    curl.on('exit', function(code) {\n        if (code != 0) {\n            console.log('Failed: ' + code);\n        }\n    });\n};\n\n/* calling the  download_file_curl function*/\ndownload_file_curl(new_file_url);\n```\n\nThis creates a local-server that is accessible at port ```3030```\n```\n/* A local sever folder is accessible via url: http://localhost:3030/. Where the osm and GeoJSON files are downloaded */\nconnect().use(serveStatic(__dirname)).listen(3030, function(){\n    console.log('Server running on 3030...');\n});\n```\n\nYou can test the GeoJSON file by accessing this url,\n```\n/* url to download the geojson file */\n// http://localhost:3030/map.geojson\n\n/* remote device via chrome browser on the sever and android */\n// https://developers.google.com/web/tools/chrome-devtools/remote-debugging/local-server\n// https://developers.google.com/web/tools/chrome-devtools/remote-debugging/\n```\n\n### Credits\nThis project uses Open Source components. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source.\n* Project: [osmtogeojson](https://github.com/tyrasd/osmtogeojson)\n\n  Author: [6+ contributors](https://github.com/tyrasd/osmtogeojson/graphs/contributors)\n\n  License: [MIT](https://github.com/tyrasd/osmtogeojson/blob/gh-pages/LICENSE)\n\n* Project: [Connect](https://github.com/tyrasd/osmtogeojson)\n\n  Author: [100+ contributors](https://github.com/senchalabs/connect/graphs/contributors)\n\n  License: [MIT](https://github.com/senchalabs/connect/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarsh%2Fosmtogeojson-nodejs-server-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakarsh%2Fosmtogeojson-nodejs-server-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarsh%2Fosmtogeojson-nodejs-server-tutorial/lists"}