Nous allons voir pour commencer mettre en place l'ensemble de fichier minimal afin de réaliser un hello-world
.
Après avoir installé NodeAtlas quelque part sur votre machine, créez-vous un ensemble de fichiers représentant un site n'importe où ailleurs comme la structure ci-dessous.
site-hello-world/
├─ templates/
│ └─ index.htm
└─ webconfig.json
Voici le fichier « /site-hello-world/templates/index.htm » :
<!DOCTYPE html>
<html lang="fr-fr">
<head>
<meta charset="utf-8" />
<title>Hello world</title>
</head>
<body>
<div>Ceci est un Hello World !</div>
</body>
</html>
et ci-après, le fichier « /site-hello-world/webconfig.json ».
Vous pouvez faire tourner une page simple avec la configuration minimale du « webconfig.json » ci-dessous
{
"routes": {
"/": {
"template": "index.htm"
}
}
}
équivalente à
{ "routes": { "/": "index.htm" } }
Placez-vous avec un invité de commande dans le dossier « /site-hello-world/ » et exécutez la commande suivante.
\> node </path/to/>node-atlas/
Vous aurez accès à votre « Hello World » à la page http://localhost/ dans un navigateur.
Si vous avez installé NodeAtlas avec npm install -g node-atlas
vous pouvez également utiliser la commande nodeatlas
. nodeatlas
est un raccourci de node </path/to/>node-atlas/
.
Placez-vous toujours avec votre invité de commande dans le dossier « /site-hello-world/ » et exécutez la commande suivante.
\> nodeatlas
Note : si la commande nodeatlas
n'est pas disponible sous unix après installation (erreur quand vous la tapez), c'est surement à cause d'un problème de droit. Si vous êtes root la commande chown -R root:root /usr/local/bin/
avant de retaper npm install -g node-atlas
solutionnera votre problème, sinon la utilisez la commande sudo npm install -g node-atlas
.*
Vous pouvez également utiliser NodeAtlas comme un module npm.
server.js
var nodeAtlas = require("node-atlas");
nodeAtlas().run();
\> node server.js