-1

Where can i find something in the documentation about "node ."?

When i run "node ." without an existing package.json file then i will get some error messages.

When i run "node ." with an existing package.json file then it opens the file defined in "main" field in package.json

Can someone explain what exactly "node ." does please?

Aznhar
  • 610
  • 1
  • 10
  • 30
mankind86
  • 11
  • 2
  • Q: Have you tried running `node -help`? If there's only one argument, it's usually treated as the name of the NodeJS script to execute. Anyway, this might help: https://nodesource.com/blog/the-basics-of-package-json-in-node-js-and-npm/ – FoggyDay Mar 20 '20 at 23:34
  • unfortunately it doenst help me – mankind86 Mar 21 '20 at 01:22
  • 1
    You're telling node to execute in the current directory. Just like when you do 'git clone .' – Nick Mar 21 '20 at 02:02
  • and where is the documentation? @NickLeBlanc – mankind86 Mar 21 '20 at 02:16
  • 1
    @mankind86 This is not part of Node documentation and it shouldn't be, it's a Unix Standard https://superuser.com/questions/37449/what-are-and-in-a-directory – Nick Mar 21 '20 at 03:05
  • 1
    @mankind86 Also if you're referring on why only 'Node .' executes something, this pretty much sums it up: https://stackoverflow.com/questions/21063587/what-is-index-js-used-for-in-node-js-projects – Nick Mar 21 '20 at 03:06

2 Answers2

1
  1. Run node -h to get a listing of command-line options. For example:

    Usage: node [options] [ -e script | script.js | - ] [arguments]
       node inspect script.js [arguments]
    
    Options:
      -                       script read from stdin (default if no
                              file name is provided, interactive mode
                              if a tty)
      --                      indicate the end of node options
      ...
    
  2. If there's only one argument, it's usually treated as the name of the NodeJS script to execute. Subsequent arguments after the script name are passed to the script. For example:

    node myapp.js myarg1 myarg2
    
  3. If there's no argument, node will go into an interactive command parser.

  4. On my NodeJS, if you type anything else (like node .) it will crash:

    d:\temp>node -v
    v10.15.1
    
    d:\temp>node .
    internal/modules/cjs/loader.js:583
        throw err;
        ^
        Error: Cannot find module 'd:\temp'
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
        at Function.Module._load (internal/modules/cjs/loader.js:507:25)
        at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
        at startup (internal/bootstrap/node.js:283:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
    
  5. Maybe different versions might behave somewhat differently. I'm not aware of any documentation for node .. But the main point is that the CLI arguments above should work with all current versions.

  6. It's definitely worth learning about package.json. Here are some useful links:

FoggyDay
  • 11,962
  • 4
  • 34
  • 48
  • `"scripts": { "start": "node .",` [source](https://developer.okta.com/blog/2018/11/15/node-express-typescript) – mankind86 Mar 21 '20 at 05:24
-1

node . is the same as node ./which refers to the current directory and executes the package.json

node ./example/sub will execute ./example/sub/package.json

mankind86
  • 11
  • 2