Is there a way to preload some file before each time I run node
(interactively), just like .vimrc
, .bash_profile
, etc.?
I use node
mainly interactively, and I use the module CSV
a lot, is there a way to avoid typing require('./csv')
every time I start node
?
@Ilan Frumer provided one way to do it. I think I'll give another choice here: build a
REPL
of your own.From their documentation. You can find a way to write a repl of your own. You can add whatever scripts before and after the interations of it, and even use some advance API's.
For example, I created a file called
.noderc.js
under~
as followsAnd you can go ahead and
alias nodei="node ~/.noderc.js"
,Create an initialization file (for example ~/.noderc):
Now add this line to your shell config (.bashrc / .zshrc / whatever shell you use):
Voilà!