Getting Started with Node, Express and Postgres Using Sequelize

入门:学习用Express, Postgress 和Sequelize搭建简单的REST服务器

Getting Started with Node, Express and Postgres Using Sequelize

JavaScript Articles

$ mkdir -p postgres-express-react-node-tutorial/{bin,server}
$ cd postgres-express-react-node-tutorial
$ npm init -y

Install Express and a few of it's dependencies.

$ npm install --save express body-parser morgan

or

$ npm i -S express body-parser morgan
$ touch app.js

we'll need a way to restart the server every time we change something in our code. For that, we'll use the excellent nodemon npm package.

$ npm i -D nodemon

Now try running the application by executing

$ npm run start:dev

We are going to be making use of the Sequelize CLI package to bootstrap the project for us. It will also help us generate database migrations.

Let's begin by installing Sequelize CLI package.

$ npm install -g sequelize-cli

we are going to need to install the actual Sequelize package, alongside its dependencies.

$ npm install --save sequelize pg pg-hstore

With the paths defined, we will need to run the init command in order to create the specified folders and generate boilerplate code.

$ sequelize init

With the models and migrations in place, we're now ready to persist the models to the database by running the migrations.

$ sequelize db:migrate

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 4,225评论 0 6
  • [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d...
    S_Lance阅读 2,887评论 1 3
  • 入门指南 1. 简介 Quickstart会让你启动和运行一个单节点单机HBase。 2. 快速启动 – 单点HB...
    _和_阅读 2,626评论 1 40
  • 我像个神经病一样发愁,难过的想死掉。好希望二宝的眼睛没事,好希望睡一觉起来什么都变好了。 心痛死了,该如何是好。
    大脸宝宝宝阅读 37评论 2 0
  • 越在意什么就会被什么伤害,体会过的人才能懂吧! 这世界有太多的解释不了,有太多的别人体会不到! 三月底考完试,放假...
    北梧南木阅读 13评论 0 0