39

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.*" } } 
6
  • 1
    It will look for server.js in your project directory and it will start your app.. Commented May 11, 2016 at 5:07
  • 1
    @Subburaj my project directory does not have a server.js file Commented May 11, 2016 at 5:10
  • @RogenGeorge: Did you really provided an argument after node? Or that dot(.) was you put by mistake? Commented May 11, 2016 at 5:14
  • 5
    The dot . in unix means the current directory. So, it would execute the default file in the given directory (index.js) Commented May 11, 2016 at 5:18
  • 1
    @aarosil sorry what do you mean by 'the default file'? Commented May 11, 2016 at 5:22

1 Answer 1

64

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I think index.js is default if package.json does not specify.
You are correct djechilin. index.js is a default file for many things like import statements in React as well.
In a loopback project it will automatically run server/server.js ! How does that work ?
@Sethunath check the main value in package.json. It says: "main": "server/server.js" that is how loopback works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.