search

Home  >  Q&A  >  body text

node.js - node服务的路径问题

加入我在根目录下的bulid目录下有一个服务器js文件,执行后将监听localhost:8080端口,然后进入这个目录执行,那么这个时候服务器根目录是在哪里呢?build下还是根目录?

伊谢尔伦伊谢尔伦2780 days ago740

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 14:47:40

    The root directory of the server is the root directory, build is just a folder, equivalent to a path

    reply
    0
  • 阿神

    阿神2017-04-17 14:47:40

    The questioner probably thought that Node.js is the same as PHP. By uploading the file directly to the server, you can access a certain URL to run the program, so he naturally struggled with the issue of relative paths.

    In fact, the routing of Node.js is registered through a program. Instead of accessing an address like /ooxx/xxoo.js, it is to run the ooxx/xxoo.js file. Similarly, static resource files are generally registered through the static middleware. to specify the root directory, so the specific method depends on how your program is written.

    reply
    0
  • Cancelreply