CS615 Lab5 Ata Gunay
CS615 Lab5 Ata Gunay
Browsers like Chrome and Firefox have runtime environments. That is why
they can run JavaScript code. Before Node.js was created, JavaScript could
only run in a browser. And it was used to build only front-end applications.
Node.js provides a runtime environment outside of the browser. It's also built
on the Chrome V8 JavaScript engine. This makes it possible to build back-end
applications using the same JavaScript programming language you may be
familiar with.
setTimeout
The callback will likely not be invoked in precisely delay milliseconds. Node.js
makes no guarantees about the exact timing of when callbacks will fire, nor of
their ordering. The callback will be called as close as possible to the time
specified.
setInterval
Resources: https://nodejs.org/api/timers.html#setintervalcallback-delay-args
clearInterval
Resources: https://nodejs.org/api/timers.html#clearintervaltimeout
The file name of the current module. This is the current module file's absolute
path with symlinks resolved.
console.log(__filename);
// Prints: /Users/mjr/example.js
Functions
var sayBye = function(){
console.log('Bye');
};
function callFunction(fun){
fun();
}
callFunction(sayBye); // Bye
To include a module, use the require() function with the name of the module:
Use the exports keyword to make properties and methods available outside
the module file.
File System
Resources: https://chat.openai.com/share/75652d74-4980-47b1-9047-
1dc4a04ae043
You can use the fs.readFile() function to read the contents of a file
asynchronously.
You can use the fs.writeFile() function to write data to a file asynchronously.
The function passed into the http.createServer() has a req argument that
represents the request from the client
NPM
Resources: https://www.w3schools.com/nodejs/nodejs_npm.asp
A package in Node.js contains all the files you need for a module.
// download
npm install upper-case
// usage
var uc = require('upper-case');
{
"name": "John Doe",
"age": 30,
"email": "[email protected]"
}
Postman is primarily used for API testing and automation, allowing developers
to create, organize, and execute API requests, monitor responses, and
collaborate with team members.
It provides a robust set of features for handling HTTP requests and responses,
routing, middleware, and more.
Express simplifies the process of building web servers and APIs by providing a
clean and intuitive API for handling common tasks.
// Define routes
app.get('/', (req, res) => {
res.send('Home Page');
});
// Start server
app.listen(3000, () => {
console.log('Server is listening on port 3000');
});