× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

NodeJS tips - hacks to make your develop easy.

Ethan
Feb 18, 2016
<p>Simple NodeJS  tips or hacks</p> <p> </p> <p><strong>npm init</strong></p> <p>Tired about npm init and then fillup the package.json?</p> <p> </p> <p>yes?</p> <pre><code class="language-bash">npm init --yes</code></pre> <p> </p> <p><strong>NVM &gt; NPM</strong></p> <p> </p> <p>So using nvm could solve 2 pottential cases (atleast on my case).</p> <p> </p> <ol> <li>Tired of sudo npm install mathjs? nvm is the solution.</li> <li>Tired to switch from node version to node version, installing- un-installing, etc? nvm is the solution.</li> </ol> <p>Never hear about <a href="https://github.com/creationix/nvm">nvm</a>? nvm is (node version manager achronymus meaning), is a library set to manage in a simple way yhe node + npm version are you using (you can also use io.js.</p> <p> </p> <p>You can simple run </p> <pre><code>nvm install 5.0 nvm use 5.0 nvm install node ## --reinstall-packages-from=node optional nvm use node nvm run system --version ## and there you got, switch from versions</code></pre> <p> </p> <p>Simple right? also now you can run npm install mathjs withouth any sudo.</p> <p> </p> <p><strong>npm install --save and ---exact</strong></p> <p> </p> <p>First you need to know that the --save flag, will autoupdate your package.json when you install a new package.</p> <p> </p> <p>Worried about maintain your app dependecies?</p> <p> </p> <pre><code class="language-bash">npm install --save --save-exact babel-register</code></pre> <p> </p> <p>This will save the dependency like</p> <p> </p> <pre><code class="language-javascript"> "dependencies": { "babel-register": "6.5.2", }</code></pre> <p> </p> <p>No more caret (<span style="background-color:rgb(240, 240, 240); color:rgb(45, 45, 45)">^),  </span>wich is a nice improvement to the way your app install dependencys</p> <p> </p> <p>This are just 3 tips, and of course there are more and more tips when we talk about nodejs.</p> <p>I find ridiculus helpful <a href="https://github.com/sindresorhus/awesome-npm">this Github Repo</a>, where there are different Articles and Tips to use in NodeJS</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus