Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up a preload file for node?

Tags:

node.js

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?

like image 254
xzhu Avatar asked Dec 25 '22 10:12

xzhu


1 Answers

Create an initialization file (for example ~/.noderc):

var csv = require('csv');

// put a blank line at the end of the file

Now add this line to your shell config (.bashrc / .zshrc / whatever shell you use):

alias nodei="cat ~/.noderc - | node -i"

Voilà!

like image 78
Ilan Frumer Avatar answered Dec 28 '22 09:12

Ilan Frumer