Difference between revisions of "Node Basics"

From rbachwiki
Jump to navigation Jump to search
Line 7: Line 7:


== Node Modules ==
== Node Modules ==
const fs = require('fs');
<pre>
  // this will require the filesystem module
console.log('starting app');
fs.appendFile('greetings.txt', 'hello', function(e){
 
  if(e){
const fs = require('fs');
      console.log('error')
const os = require('os');
        }
var user = os.userInfo();
});
  //console.log(user);
fs.appendFile('greet.txt', `hello${user.username}!` , (e)=>{
    if(e){
        console.log('error');
    }
});
</pre>


[https://nodejs.org/api/ Nodejs api List]
[https://nodejs.org/api/ Nodejs api List]
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[NodeJS|Category]]==
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[NodeJS|Category]]==

Revision as of 23:43, 2 April 2018

Run a Node App

terminal

node filename.js

You can execute node code in the terminal by typing

node 

This will give you a node command prompt

Node Modules

console.log('starting app');

const fs = require('fs');
const os = require('os');
 var user = os.userInfo();
 //console.log(user);
fs.appendFile('greet.txt', `hello${user.username}!` , (e)=>{
    if(e){
        console.log('error');
    }
});

Nodejs api List

Back To Top- Home - Category