How to create directory using npm init


when i type npm init in bash it does not create package.json in exercise 5/11
but in exercise 11/11 when i run same command it is able to do so.

also can i create src directly from bash terminal using npm init?


npm is just a command line program. Given this program has been written, it does certain things. If you just want to create a directory you could use mkdir in bash.


i am confused in the command npm init.
from the lecture what i infered was that just by typing npm init in bash i should be able to create a file package.json. but it seems to be incorrect.
typing that gives be some pointers on how i can use npm commands. And it seems inorder to create a file package.json i need to type either npm install babel-cli or npm install babel-preset-env

maybe im getting stuck on the formalities of the program which does not need to be pondered upon much?


Here’s what running npm init and pressing enter for all prompts looks like.

If you’re not getting anything like this, what do you get? Perhaps you’re running something else.
Or perhaps npm tells you exactly what’s wrong if you only read the response more carefully


i get the part till press ^C at any time quit.
is it because im running bash inside the codeacademy browser ?

i had actually deleted the file package.json to see if i can create it using npm init, however after deletion was unable to create a package.json


Sounds like it’s waiting for input…Give it input.


thanks a lot, i finally understood, wasnt paying attention below the control+c break line. where it was waiting for input. was using the text editor to make those changes- as required in the exercises.

ok so one just one confusion, the file doesnt appear immediately in the text editor file tree. however a refresh fixes that. is it because of low ram or a browser compatibility issue?

edit- ok so the file gets created immediately if i press y- on command line is this ok?
only doesnt get created if it is aborted, or if i press ctrl+c anytime before that.



control + c is the interrupt signal, to interrupt a running program like npm.

Could just be the lesson, nothing to worry about it.

the npm program is cleverly written, very likely it accepts both y and yes and maybe even ye

If i tell you to stop (which is what ctrl + c does), you don’t finish the task either, just like npm


The file will get created at the very latest when npm exits (right before you’re back at the bash prompt) because the os frees up the resources of that process which includes the open file handle, though likely before that because while quitting, or perhaps even before that, npm will probably be asking the os to flush the file buffers (rather than writing a single byte at a time, they get processed in chunks (faster to process a lot at once))

Rather than answering “y”, leave the defaults