This repository for training class REST API with Node.js by LOXMAN.
- Fork this repository to your repository.
- Install NVM with this link each OS and use Node.js LTS version.
nvm install --lts
nvm use --lets- Install Postman application for call test API.
- Les't go in class for REST API with Node.js
npm init- Run this command
npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/node- Create new file '.babelrc' and add present in this file
{
"presets": ["@babel/preset-env"]
}- Install Express.js
npm install express- Add new src directory
- Setup Express.js in this workspace
import express from 'express';
const app = express();
const port = 3000;
app.use(express.json());
app.use(express.urlencoded({
extended: true,
})
);
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})- Open file new package.json.
- Add script build and start in this file.
"scripts": {
"build": "babel src --out-dir dist",
"Start": "node dist/main.js"
}npm run build
npm run startPlease commit with this link and link this project usage commit templates is
<type>(<scope>): <subject>
<body>
<footer>fix(middleware): ensure Range headers adhere more closely to RFC 2616
Add one new dependency, use `range-parser` (Express dependency) to compute
range. It is more well-tested in the wild.
Fixes #2310The first line cannot be longer than 70 characters, the second line is always blank and other lines should be wrapped at 80 characters. The type and scope should always be lowercase as shown below.
build: Build related changes (eg: npm related/ adding external dependencies)chore: A code change that external user won't see (eg: change to .gitignore file or .prettierrc file)feat: A new featurefix: A bug fixdocs: Documentation related changesrefactor: A code that neither fix bug nor adds a feature. (eg: You can use this when there is semantic changes like renaming a variable/function name)perf: A code that improves performancestyle: A code that is related to stylingtest: Adding new test or making changes to existing test
initrunnerwatcherconfigweb-serverproxy- etc.
The can be empty (e.g. if the change is a global or difficult to assign to a single component), in which case the parentheses are omitted. In smaller projects such as Karma plugins, the is empty.
- uses the imperative, present tense: “change” not “changed” nor “changes”
- includes motivation for the change and contrasts with previous behaviour
Closed issues should be listed on a separate line in the footer prefixed with "Closes" keyword like this:
Closes #234
or in the case of multiple issues:
Closes #123, #245, #992
All breaking changes have to be mentioned in footer with the description of the change, justification and migration notes.
BREAKING CHANGE:
`port-runner` command line option has changed to `runner-port`, so that it is
consistent with the configuration file syntax.
To migrate your project, change all the commands, where you use `--port-runner`
to `--runner-port`.