{
"name": "Basic Node and Express",
"order": 2,
"time": "5 hours",
"helpRoom": "Help",
"challenges": [
{
"id": "587d7fb0367417b2b2512bec",
"title": "Introduction to the Basic Node and Express Challenges",
"description": [
[
"",
"",
"Node.js is a JavaScript tool that allows developers to write backend (server-side) programs in JavaScript. Node.js comes with a handful of built-in modules--small, independent programs--that help facilitate this purpose. Some of the core modules include:
\"Hello World\"
should be in the console",
"testString" : "getUserInput => $.get(getUserInput('url') + '/_api/hello-console').then(data => { assert.isTrue(data.passed, '\"Hello World\" is not in the server console'); }, xhr => { throw new Error(xhr.responseText); })"
}
],
"solutions": [],
"hints": [],
"type": "backend",
"challengeType": 0,
"translations": {}
},
{
"id": "587d7fb0367417b2b2512bee",
"title": "Start a working Express Server",
"description": [
"In the first two lines of the file myApp.js you can see how it’s easy to create an Express app object. This object has several methods, and we will learn many of them in these challenges. One fundamental method is app.listen(function(req, res) {
",
" res.send('Response String');
",
"}
",
"will serve the string 'Response String'.",
"Use the app.get() method to serve the string Hello Express, to GET requests matching the / root path. Be sure that your code works by looking at the logs, then see the results in your browser, clicking the button ‘Show Live’ in the HyperDev UI."
],
"challengeSeed": [],
"tests": [
{
"text" : "Your app should serve the string 'Hello Express'",
"testString" : "getUserInput => $.get(getUserInput('url')).then(data => { assert.equal(data, 'Hello Express', 'Your app does not serve the text \"Hello Express\"'); }, xhr => { throw new Error(xhr.responseText); })"
}
],
"solutions": [],
"hints": [],
"type": "backend",
"challengeType": 0,
"translations": {}
},
{
"id": "587d7fb0367417b2b2512bef",
"title": "Serve an HTML file",
"description": [
"We can respond with a file using the method res.sendFile(/public
directory",
"testString" : "getUserInput => $.get(getUserInput('url') + '/style.css').then(data => { assert.match(data, /body\\s*\\{[^\\}]*\\}/, 'Your app does not serve static assets'); }, xhr => { throw new Error(xhr.responseText); })"
}
],
"solutions": [],
"hints": [],
"type": "backend",
"challengeType": 0,
"translations": {}
},
{
"id": "587d7fb1367417b2b2512bf1",
"title": "Serve JSON on a specific route",
"description": [
"While an HTML server serves (you guessed it ?) HTML, an API serves data. A REST API allows data exchange in a simple way, without the need for clients to know any detail about the server. The client only needs to know where the resource is (the URL), and the action it wants to perform on it (the verb). The GET verb is used when you are fetching some information, without modifying anything. In these days the preferred data format to move these informations around the web is JSON. In few words JSON is a convenient way to represent a JavaScript object as a string, so it can be easily transmitted.",
"Let’s create a route that responds with JSON at the path (/json). You can do it as usual, with the app.get() method. Inside the route handler use the method res.json(