如何解决运行NodeJs程序时出现的错误

时间:2019-12-24 09:53:43

标签: node.js

我正在尝试将geojson文件转换为shapefile。但是运行此代码后,我收到此错误。我该如何解决??

................... server.js
var geojson2shape = require('geojson2shape')
// a shapefile is actually multiple files. geojson2shape will output a zipped version if specified.
var zip = true
geojson2shape(__dirname+'/polygon.geojson', __dirname+'/polygon.shp', function(err){
  if(err) throw err
})
..................  error

events.js:187
      throw er; // Unhandled 'error' event
      ^

  Error: ENOENT: no such file or directory, open 'C:\test\polygon.dbf'
  Emitted 'error' event on ReadStream instance at:
    at internal/fs/streams.js:120:12
    at FSReqCallback.oncomplete (fs.js:146:23) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\test\\polygon.dbf'
}

1 个答案:

答案 0 :(得分:0)

该错误可能是由于以下任一原因导致的,一一检查:-

1.fs.readFile() is async, if you are using this you need to pass
 callback as well. OR you can try readFilesync()

2.The error is due to the incorrect file location('C:\test\polygon.dbf') 

3.file doesn't have read permission.You can try with any other file path.
  

当您尝试读取数据库文件时,可以尝试一些DBF   解析器npm模块,用于读取或对其进行任何其他操作。

我可以建议您为 node-dbf

  

npm i node-dbf

     

you can checkout this link for more info

希望这会有所帮助!