0

I'm completely new to Node.js so I have I question.

I'm writing a simple cli app that will create some files and directories.

For example if user inputs :

name-of-my-app init

It will create index.html with some html markup with indentation(like !DOCTYPE, head, body etc.)

Maybe I can create a file and then just move the ready file from my node_modules/my-app directory to the directory of the user(__dirname)?

The idea of my cli app is to init new projects with some .css and .js files. Also I want to use it globally(npm install -g my-app)

Hope you'll understand what I mean :)

Any advices?

Thank you very much for spending your precious time with my problem!

  • 2
    Yes; it is possible to create or copy files. What don't you understand? – SLaks Feb 28 '18 at 16:20
  • 2
    I'm not sure I understand what's your question. What problem are you facing? – Federico klez Culloca Feb 28 '18 at 16:20
  • @SLaks Well, sorry for not clearing it out. I mean if it's possible to just copy some files from app directory to user's I don't understand how can I grab the while from app directory while using my app globally? –  Feb 28 '18 at 16:21
  • @YegorGunko: So you're actually just asking how to get the path to the current file? Use `__dirname`. – SLaks Feb 28 '18 at 16:22
  • @SLaks, yeah I mean if I use __dirname for grab a file then how to access directory in which user is 'staying' and place the file there? –  Feb 28 '18 at 16:23
  • https://stackoverflow.com/q/3133243/34397 – SLaks Feb 28 '18 at 16:24
  • @SLaks sorry for troubling you with stupid questions, but I still can't understand if I use my app globally the __dirname will refer to my app's root directory? Like : /usr/lib/node_modules/my-app? –  Feb 28 '18 at 16:27
  • You're looking for the current directory, not `__dirname`. – SLaks Feb 28 '18 at 16:58

1 Answers1

2

You should check out Yeoman. It Might be more suited to what you want.

Stretch0
  • 8,362
  • 13
  • 71
  • 133