简体   繁体   中英

What does the command “node .” do?

The README document of my node server instructs me to run this command on my command prompt.

node .

What does this command do? How does it start my node server?

My package.json contents are

{
  "name": "uber-api",
  "version": "1.0.0",
  "description": "Move your app forward with the Uber API",
  "main": "index.js",
  "keywords": [
    "swagger"
  ],
  "license": "MIT",
  "private": true,
  "dependencies": {
    "connect": "^3.2.0",
    "js-yaml": "^3.3.0",
    "swagger-tools": "0.9.*"
  }
}

By default Node.js is trying to load a module located in the folder that you are passing to it as an argument ( . - just bash variant of the current folder). Then it runs whatever is written in the "main" section of the package.json file found in this folder.

In your case, it'll try to run node ./index.js

Doc: https://docs.npmjs.com/files/package.json#main

Good point from @djechlin : if no package.json found in the folder or if no "main" section is present, then Node.js will try to run the index.js file in this particular folder you are passing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM