Introduction to Node.js
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
https://nodejs.org/en/
First code
// index.js
console.log('Hello World');
$ node index.js
// index.js
const Fs = require('fs');
console.log(Fs.readdirSync('./'));
Fs.readdir('./', (err, content) => {
console.log(err);
console.log(content);
});
console.log('hello');
$ node index.js
// index.js
const Http = require('http');
const server = Http.createServer((req, res) => {
res.end('hello: ' + req.url);
});
server.listen(8080);
$ node index.js
can you build a simple file serving tool?
express
$ npm init
$ npm install --save express
const Express = require('express');
const app = Express();
app.get('/hello', (req, res) => {
res.end('hello');
});
app.get('/', (req, res) => {
res.end('foo');
});
app.get('/bar', (req, res) => {
res.end('bar');
});
app.listen(8080);
app.get('/hello/:name', (req, res) => {
res.end('hello ' + req.params.name);
});
TODO: a POST route
SQLite3
$ npm i -S sqlite3
TODO: CRUD in DB
Clean repo
Controller
Service
View
Data Validation
Joi!
Check out the packages
- Joi
- Celebrate
Testing?
Check out the pacakges
- lab
- code
- supertest
intro-nodejs
By Vladimir de Turckheim
intro-nodejs
- 1,135