Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.*"   } } 
like image 661
Rogen George Avatar asked May 11 '16 05:05

Rogen George


People also ask

What is node and why it is used?

Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.


1 Answers

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.

like image 113
Yuri Tkachenko Avatar answered Sep 30 '22 23:09

Yuri Tkachenko