Skip to content

koodi101/lesson3-nodejs-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lesson 3: NodeJS Template

This is the repository for a simple Node.js chat application using koa (a web server framework) and sequelize, which maintains the SQLite database.

Prerequisites

You can run the example with Node.js (or Docker).

Node.js is a programming language based on JavaScript which allows you to read files, create processes and run server software. Regular JavaScript is run within a web browser and has no access to the filesystem or processes.

To query the server we suggest using HTTPie. Install the HTTPie Desktop application, or go with just the command-line tool if you want.

Running the example

After forking and cloning the repository, you have to change your working directory so that Node.js can find the required files, like package.json and the src directory.

cd lesson3-nodejs-template

To confirm you are in the correct directory, use the command

ls

You should now see something similar to

$ ls
backend  docker-compose.yml  README.md

cd means change directory and ls is short for list.

The dollar sign $ indicates that the following text is a command executed by the shell.

Running with plain Node.js

npm install
npm run dev

Exercises

The app

  • Use HTTPie to
    • Post a new message to /api/chats
    • Get the messages from /api/chats

httpie

For more information on how to use the HTTPie CLI, refer to the official documentation.

Deploy

  • Use SSH keys to login to the server
  • Install needed dependencies on the server
    • node
    • tmux
  • Start a tmux session
  • Run npm start
  • (Detach CTRL-B D and log out CTRL-D)

Note: Deploying production software services using tmux and a shell is not recommended. This guide is only for getting up to speed.

Optional homework

  • Add nickname and chat rooms to messages
  • Create a new endpoint /api/chats/<room> that returns messages for specific room
  • Commit your changes and deploy them over SSH.

About

Lesson 3: The first backend application using node and koa.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published