Update for 18-11-21 21:30

This commit is contained in:
Tyler Perkins 2021-11-18 21:30:01 -05:00
parent 21f58a208c
commit 151d4bd0c8
3 changed files with 67 additions and 2 deletions

View File

@ -3,6 +3,9 @@
Javascript is probably the most popular language in existance. It is an
interpreted, typeless language
== Node ==
== Backend ==
See [[Node.js.wiki]] for the core runtime of backend js (node)
See [[../tech/express.js.wiki]]
See [[Node.js.wiki]]

View File

@ -53,3 +53,57 @@ where a pointer is assigned then later called through the pointer.
The file system can be read in two modes, either in a block or non blocking
mode (similar to async calls in C#)
Below is an example of exactly that. The 'Sync' calls are ones that are done in
a blocking manner
{{{
//import read file
const { readFile, readFileSync } = require('fs');
//read the file, blocking
const txt = readFileSync('./sample.txt', 'utf8');
console.log(txt);
//or read the file on a seperate thread
//the third argument is the file name, encoding, then the function (which gets
//passed both the error object, and the contents of the file)
readFile('./sample.txt', 'utf8', (err, txt) => {
//stuff to do after we get the file
console.log(txt)
});
console.log('this is called after the fact');
}}}
== Packages ==
Node.js's package manager is npm. It can download packages for you to use in
your project. To start using npm in a project, run `npm init -y` to setup a
package.json file, which is how npm keeps track of files it needs. Now to
install a framework (for example, express), run `npm install express`, and
thats all that is needed
To include a package (which includes the several built in packages), use the
`require()` syntax, and pass it a string argument of the name of the module.
This system is how you can use several files on one project. To include a
module called 'my-module', you first create a my-module.js file, the add this
to the top of your code
{{{
const myModule = require('./my-module');
console.log(myModule);
}}}
Then in the module file you must export code from it. In the module file, add
the following
{{{
module.exports = {
myvar : 'some value'
}
}}}
Now myModule.myvar will return 'some value'. You can use functions and the like
here to make easy to import functionality.

8
tech/express.js.wiki Normal file
View File

@ -0,0 +1,8 @@
= Express.js =
Express.js is a web framework for node.js, for making full stack web
applications.
== Hello World ==
Below is a hello world application, that responds on the root directory.